REST – Retrieve Multiple Example

Retrieve Multiple

Syntax: SDK.REST.retrieveMultipleRecords(type, options, successCallback, errorCallback, OnComplete)

Name Type Description
type String The Schema Name of the Entity type record to retrieve.
options String A String that represents the OData System Query Options to control the data returned.
successCallback Function The function that will be passed through and be called for each page of records returned.
This example uses the retrieveContactsCallBack function.
errorCallback Function The function that will be passed through and be called by a failed response.
This example uses the errorCallBack function.
OnComplete Function The function that will be called when all the requested records have been returned.
This example uses the contactsRetrieveComplete function.

Task:  Retrieve all Contacts contains MobilePhone data
Solution: Add the below Script in “new_sdkOperations” Webresource and click Ok.

Please do check REST – Retrieve for Initial Setup.

function retrieveMultipleContacts() {
var options = "$select=FullName,MobilePhone&$filter=MobilePhone ne null"; //Write your own Query to get Records
SDK.REST.retrieveMultipleRecords("Contact", options, retrieveContactsCallBack, errorCallBack, contactsRetrieveComplete);

function retrieveContactsCallBack(retrievedContacts) {
var outputString = "";
outputString = "FullName\t\t\tMobile Phone\n";
outputString = outputString + "--------------------------------------------------\n";
for (var i = 0; i < retrievedContacts.length; i++) {
outputString = outputString + retrievedContacts[i].FullName + " \t " + retrievedContacts[i].MobilePhone + "\n";

function errorCallBack(error) {

// This function is called after all the records have been returned
function contactsRetrieveComplete() {

Add OnLoad event in Contact Form, Library: new_sdkOperations & function retrieveMultipleContacts. Save and Publish


Open any Contact Record to see the below output,


Please provide your valuable comments on this article.


4 thoughts on “REST – Retrieve Multiple Example

  1. Dear Arun Potti,

    Thank you for the example. It worked perfectly.

    I am however, stuck at a point where I cannot cancel a Form save event within my REST call. It works fine when executed outside the REST call.

    Here is my code snippet:

    function TSOCheckForProducts(ExecutionObj) {
    var Products = 0;
    var opportunityid =;
    “$select=PricePerUnit&$filter=OpportunityId/Id eq (guid'” + opportunityid + “‘) and (new_ProductService eq false)”,
    function (results) {
    Products = results.length;
    function (e) { //on error
    function () { //on Complete
    ExecutionObj.getEventArgs().preventDefault(); //This does NOT work

    ExecutionObj.getEventArgs().preventDefault(); //This works

    Now, how do I prevent form close event??



      • Hi Arun,

        Thank you for replying back.

        Consider the following example:
        I have form in CRM 2011 called ‘Contacts’.
        Now in this form, if a user enters data in some fields and then clicks on ‘Save & Close’, then I wish to cancel his form close event i e. prevent the user from saving and closing the form.

        For this I am using the following line of code:

        Now, this code does not work when called inside the successCallback function of REST’s retrieveMultipleRecord().

        However, it works successfully when called outside the successCallback function.

        Now, How do I make that line of code work inside REST method??


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.