Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

SDK.REST.retrieveRecord failing to retrieve the value

Posted on by Microsoft Employee

I have an issue with an SDK.REST.retrieveRecord call.  I'm not getting a value back and can't seem to get "inside" the call to determine what the problem is.  Here are two functions, one is a custom form with a Lookup field referencing the Case.  It retrieves the Case ID (incidentid) without any trouble.  (I verified it was correct because it also returns the Case (Name).)

var incid = thisCase.getAttribute().getValue()[0].id;

var cn = getCaseNumber(incid);    //incid IS the GUID for this Case

function getCaseNumber(incidentid) {

var incident = {};

var casenum = "";

SDK.REST.retrieveRecord(

incidentid,

"Case",

null, null,

function (incident) {

casenum = incident.ticketnumber;

},

function () {

alert("ERROR: getCaseNumber for " + incidentid.toString());

}

);

return casenum;

}

casenum is always blank, although I know the Case Number (ticketnumber) is in there.

I am not getting an error so it must be hitting the Success block.  I was getting an error earlier when I had a wrong parameter so I know at least the Error block is functioning correctly.  I have also used both the fieldname (ticketnumber) and SchemaName (TicketNumber) for the field.

Any thoughts?

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SDK.REST.retrieveRecord failing to retrieve the value

    This worked on my dev machine (one Organization), but my client has more than one, which changes the URL and I get a "file not found" error.  Here are the details:

    In my dev env, Xrm.Page.contect.getClientUrl() + "/XrmServices/2011/OrganizationData.svc/INcidentSet(guid'" + caseId + "')?...

    returns:

    crmdev/.../IncidentSet(guid'{25849C8D-DCA7-E411-871C-000C29F61EFB}')

    The CRM Services are located at:

    C:\Program Files\Microsoft Dynamics CRM\CRMWeb\XRMServices\2011\OrganizationalData.svc

    At my client it returns:

    localhost/.../IncidentSet(guid'{6C5842F4-2370-E411-80C7-00155D307902}')

    *--single server instance, so localhost works for the CRM

    The CRM Services at the client are located at:

    C:\Program Files\Microsoft Dynamics CRM\CRMWeb\XRMServices\2011\OrganizationData.svc

    BUT

    When I get the error back, it is looking in

    C:\Program Files\Microsoft Dynamics CRM\CRMWeb\LRF\XRMServices\2011\OrganizationData.svc

    I have attempted to modify the clientUrl to just be http://localhost, but that fails as well since it needs the organization.

    The error description is:

    This error means that the file or directory does not exist on the server. Create the file or directory and try the request again.

    Any thoughts?

  • JohnLeme Profile Picture
    JohnLeme 355 on at
    RE: SDK.REST.retrieveRecord failing to retrieve the value

    You must update your sdk.rest.js file. Download the latest sdk and update. The difference is that getServerUrl() has been replaced by getClientUrl().

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SDK.REST.retrieveRecord failing to retrieve the value

    Thanks Chitra - that worked.  I'm still curious as to why the other code did not, but I have no time to wonder...must move on.

  • Verified answer
    Royal King Profile Picture
    Royal King 27,686 on at
    RE: SDK.REST.retrieveRecord failing to retrieve the value

    Try with below script function, it should work

    function getCaseNumber(caseId) {
    var req = new XMLHttpRequest();
    req.open("GET", encodeURI(Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/IncidentSet(guid'" + caseId + "')?$select=TicketNumber,Title"), false);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.send();
    var result = JSON.parse(req.responseText).d;
    return result.TicketNumber;
    // var Title = result.Title;
    }

     

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SDK.REST.retrieveRecord failing to retrieve the value

    Yeah - sorry, I tried that too.  Forgot to change this message to the current version of the code.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 229,928 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans