locked
How can i use the retrieve multiple using sdk retrieveMultipleRecords: function (type, options, successCallback, errorCallback, OnComplete) RRS feed

  • Question

  • Hi there I was using the sdk 2013 Odata Sample 

     retrieveMultipleRecords: function (type, options, successCallback, errorCallback, OnComplete) {
      ///<summary>
      /// Sends an asynchronous request to retrieve records.
      ///</summary>
      ///<param name="type" type="String">
      /// The Schema Name of the Entity type record to retrieve.
      /// For an Account record, use "Account"
      ///</param>
      ///<param name="options" type="String">
      /// A String representing the OData System Query Options to control the data returned
      ///</param>
      ///<param name="successCallback" type="Function">
      /// The function that will be passed through and be called for each page of records returned.
      /// Each page is 50 records. If you expect that more than one page of records will be returned,
      /// this function should loop through the results and push the records into an array outside of the function.
      /// Use the OnComplete event handler to know when all the records have been processed.
      /// </param>
      ///<param name="errorCallback" type="Function">
      /// The function that will be passed through and be called by a failed response. 
      /// This function must accept an Error object as a parameter.
      /// </param>
      ///<param name="OnComplete" type="Function">
      /// The function that will be called when all the requested records have been returned.
      /// No parameters are passed to this function.
      /// </param>
      this._stringParameterCheck(type, "SDK.REST.retrieveMultipleRecords requires the type parameter is a string.");
      if (options != null)
       this._stringParameterCheck(options, "SDK.REST.retrieveMultipleRecords requires the options parameter is a string.");
      this._callbackParameterCheck(successCallback, "SDK.REST.retrieveMultipleRecords requires the successCallback parameter is a function.");
      this._callbackParameterCheck(errorCallback, "SDK.REST.retrieveMultipleRecords requires the errorCallback parameter is a function.");
      this._callbackParameterCheck(OnComplete, "SDK.REST.retrieveMultipleRecords requires the OnComplete parameter is a function.");
    
      var optionsString;
      if (options != null) {
       if (options.charAt(0) != "?") {
        optionsString = "?" + options;
       }
       else
       { optionsString = options; }
      }
      var req = new XMLHttpRequest();
      req.open("GET", this._ODataPath() + type + "Set" + optionsString, true);
      req.setRequestHeader("Accept", "application/json");
      req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
      req.onreadystatechange = function () {
       if (this.readyState == 4 /* complete */) {
        req.onreadystatechange = null;
        if (this.status == 200) {
         var returned = JSON.parse(this.responseText, SDK.REST._dateReviver).d;
         successCallback(returned.results);
         if (returned.__next != null) {
          var queryOptions = returned.__next.substring((SDK.REST._ODataPath() + type + "Set").length);
          SDK.REST.retrieveMultipleRecords(type, queryOptions, successCallback, errorCallback, OnComplete);
         }
         else
         { OnComplete(); }
        }
        else {
         errorCallback(SDK.REST._errorHandler(this));
        }
       }
      };
      req.send();
     },
    


    what are the steps to use the above function for the following code to check for the existing phone

    function ValidateContactInformation(econtext)
    {
    if(Xrm.Page.getAttribute("telephone1") != null)
    {
    if(Xrm.Page.getAttribute("telephone1").getValue() != null)
    {
    var mobileNumber = Xrm.Page.getAttribute("telephone1").getValue();
    var serverUrl = Xrm.Page.context.getServerUrl();
    var oDataEndpointUrl = serverUrl + "/XRMServices/2011/OrganizationData.svc/";
    oDataEndpointUrl += "ContactSet?$select=Telephone1&$filter=Telephone1 eq '" + mobileNumber + "'";
    var service = GetRequestObject();
    if(service != null)
    {
    service.open("GET", oDataEndpointUrl, false);
    service.setRequestHeader("X-Requested-Width", "XMLHttpRequest");
    service.setRequestHeader("Accept", "application/json, text/javascript, */*");
    service.send(null);
    if (service.status != 200)
    {
    alert("Unable to get Bill To Information using OData Call. ");
    return;
    }
    var requestResults = eval('(' + service.responseText + ')').d;
    if(requestResults != null)
    {
    if(requestResults.results[0] != null)
    {
    alert("This Phone number is already exist please try to set another one. thanks");
    econtext.getEventArgs().preventDefault();
    //Xrm.Page.context.getEventArgs().preventDefault();
    }
    }
    }
    }
    }
    }

    function GetRequestObject()
    {
        if (window.XMLHttpRequest)
        {
            return new window.XMLHttpRequest;
        }
        else
        {
            try
            {
                return new ActiveXObject("MSXML2.XMLHTTP.3.0");
            }
            catch (ex)
            {
                return null;
            }
        }
    }



    • Edited by Crm_2013 Saturday, January 4, 2014 2:23 PM
    Saturday, January 4, 2014 2:08 PM