Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

SDK.REST.retrieveMultipleRecords

Posted on by 2,665
 Hi,

I need some guidance with SDK.REst retrievemultiplerecords script that I am trying to write.

I am querying incident entity to retrieve a custom date field value into the child entity on load of the form. Once I get the date, I will require or not require some of the fields on child entity form.

BUt I am unable to get the results from parent entity using SDK.Rest.retrievemultiplerecords.

Here is my script:

function require()
{
debugger;

  var incidentId;
var replacedEncounterId;
if (Xrm.Page.data.entity.attributes.get("new_incidentid").getValue() != null) {

           incidentid= Xrm.Page.data.entity.attributes.get("new_incidentid").getValue()[0].id;
           replacedIncidentId=incidentid.replace('{', '').replace('}', '')
}

SDK.REST.retrieveMultipleRecords(
 "Incident",
 "$select=new_eventdate&$filter=incidentid eq guid '" + replacedIncidentId+ "'",
function onSuccess(results){
debugger;
var firstResult=results[0];
}
,
 function errorHandler(error) {
 writeMessage(error.message);
}
,
 onCompleteHandler
 );


}

Thanks for any help!

*This post is locked for comments

  • gdas Profile Picture
    gdas 50,085 on at
    RE: SDK.REST.retrieveMultipleRecords

    As far as I know SDK.Rest has not been deprecated yet  but probably coming days its should be deprecated.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SDK.REST.retrieveMultipleRecords

    Hi Team,

    My question here is SDK.Rest is not deprecated in D365 right?

    Because it is still included in D365 SDK.

    Thanks and Regards,

    Pooja Patel

  • amritesh Profile Picture
    amritesh 360 on at
    RE: SDK.REST.retrieveMultipleRecords

    Hi,

    Can you try this query using sync call? let us know if you still facing status as 0.

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: SDK.REST.retrieveMultipleRecords

    Hi ,

    Seems your code is correct , however I did some modification try with this. In addition I have given here one hard code commented line , you can try with some hard code value .

    I am assuming that there is some issue with retrieving the id from the lookup . Make sure field name is correct , also I have put another debugger in the result area you can try to debug your code and share the error you are getting .

            function require() {
                debugger;
                var incidentId;
                var replacedincidentId;
                if (Xrm.Page.getAttribute("new_incidentid").getValue() != null) {
    
                    incidentId = Xrm.Page.getAttribute("new_incidentid").getValue()[0].id;
                    replacedincidentId = incidentId.replace('{', '').replace('}', '');
                }
                var req = new XMLHttpRequest();
                // req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.1/incidents(46FE098F-8049-E811-A94E-000D3A37870E)?$select=title", true);
                req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.1/incidents(" + replacedincidentId + ")?$select=title", true);
                req.setRequestHeader("OData-MaxVersion", "4.0");
                req.setRequestHeader("OData-Version", "4.0");
                req.setRequestHeader("Accept", "application/json");
                req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
                req.onreadystatechange = function () {
                    if (this.readyState === 4) {
                        req.onreadystatechange = null;
                        if (this.status === 200) {
                            debugger;
                            var result = JSON.parse(this.response);
                            var title = result["title"];
                        } else {
                            alert(this.statusText);
                        }
                    }
                };
                req.send();
            }


  • Suggested answer
    Justinjose Profile Picture
    Justinjose 2,707 on at
    RE: SDK.REST.retrieveMultipleRecords

    Hi roxanna,

    There is nice tool called CRM Rest builder. This will help to build Web Api Script, also you can pass guid and see the results in real time.

    github.com/.../CRMRESTBuilder

    Thanks

    Justin Jose

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: SDK.REST.retrieveMultipleRecords

    Can you please check the value of replacedincidentId before calling the request? Is it giving you anything?

    Also, add a semicolon after the line replacedincidentid=...

  • crmprogrammer2013 Profile Picture
    crmprogrammer2013 2,665 on at
    RE: SDK.REST.retrieveMultipleRecords

    Sure, Aric. I will simplify the script as you suggested. However, that part is working completely fine.

    Its the rest query request and response is not working. I just now tried using oData web api and it is giving me status as 0 and status text as ' '.

    I am not sure what else to try!

    Here is my updated script:

    function require()
    {
    debugger;
    
      var incidentId;
    var replacedincidentId;
    if (Xrm.Page.getAttribute("new_incidentid").getValue()!= null) {
    
               incidentId= Xrm.Page.getAttribute("new_incidentid").getValue()[0].id;
               replacedincidentId=incidentId.replace('{', '').replace('}', '')
    }
    
    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.1/incidents("+replacedincidentId+")?$select=title", true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.onreadystatechange = function() {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 200) {
                var result = JSON.parse(this.response);
                var title = result["title"];
               }
            else {
                alert(this.statusText);
            }
        }
    	};
    
    req.send();
    
    
    }


    Thank you.

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: SDK.REST.retrieveMultipleRecords

    Are you getting any errors. I see you added debugger, so what is happening when you look at your code.

    Also, a couple things in your if statement. You can make it a little easier:

    You can use Xrm.Page.getAttribute() instead of Xrm.Page.data.entity.attributes.get()

    if (Xrm.Page.getAttribute("new_incidentid").getValue() != null) {

              incidentid= Xrm.Page.getAttribute("new_incidentid").getValue()[0].id;

              replacedIncidentId=incidentid.replace('{', '').replace('}', '')

    }

    Do you know where exactly it is breaking?

  • crmprogrammer2013 Profile Picture
    crmprogrammer2013 2,665 on at
    RE: SDK.REST.retrieveMultipleRecords

    I have been trying XMLHttpRequest to retrieve data in the past. But it has always caused me headaches as it works sometimes and won't some other time. I usually get server error(500). So, I've been looking around for other methods and I found SDK.REST and wanted to try. Honestly, I didn't know it is going to be deprecated eventually. But then why did they include SDK.REST in CRM 365 SDK sample code folders if it is going to be deprecate?

    Anyways, my sincere apologies for asking such dumb questions.

    Regarding my issue, I am doing something simple but not getting results. All I need is a field value from parent entity to child entity on load of the child form.

    Please guide me through this.

    Thank you.

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: SDK.REST.retrieveMultipleRecords

    Hi Roxanna,

    Why are you using SDK.REST with CRM 2016?

    CRM 2016 uses the oData WebApi, and although I am not sure when, the Organization Service will be eventually deprecated.

    You also don't need to include an external library in your code file.

    You can use CRM Rest Builder to build your API queries:

    github.com/.../CRMRESTBuilder

    Hope this helps.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans