locked
Need inputs on Filtered Query in RetriveMultiple (REST) with JavaScript RRS feed

  • Question

  • Hi,

    I have a requirement explained as below.

    I will be having Contact Full Name and Email Address from a method and I need to check if that contact is already present in the CRM. If present in CRM, assigning the existing contact to my required entity or else create a new contact with the information and assign it to my required entity.

    I was trying to achieve it using RetrieveMultiple (REST) in my JavaScript.

    Can anybody help me with this code on how to write the filtered query in my RetrieveMultiple and return the values to other method where I could assign and proceed with the next steps.

    Any help would be highly appreciated.

    Thanks,

    Sri.

    Monday, November 24, 2014 5:52 AM

All replies

  • Hi Sri,

    You would make a REST-call that looks pretty much like this:

    var serverUrl = Xrm.Page.context.getClientUrl();
    
      
     // Creating the Odata Endpoint
        var oDataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
        var retrieveReq = new XMLHttpRequest();
        var Odata = oDataPath + "/ContactSet?$filter=FullName eq'" + fullName + "' and EMailAddress1 eq '" + email + " '";
        retrieveReq.open("GET", Odata, false);
        retrieveReq.setRequestHeader("Accept", "application/json");
        retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        retrieveReq.onreadystatechange = function () { retrieveReqCallBack(this); };
        retrieveReq.send();,
        var retrieved = this.parent.JSON.parse(retrieveReq.responseText).d;
    if(retrieved.results.Count() == 1)
    {
     **do stuff**
    }
    }
    
    

    I can't verify the count-part atm but the rest should be working.

    Hope this helps


    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

    Monday, November 24, 2014 1:30 PM
  • You could also use this tool to help build REST based queries in CRM: 

    https://crmrestbuilder.codeplex.com/


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Monday, November 24, 2014 2:00 PM
    Moderator