web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

SDK.REST.retrieveRecord failing to retrieve the value

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Community Member Profile Picture
    on at

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

  • Verified answer
    Royal King Profile Picture
    27,686 on at

    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
    on at

    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.

  • JohnLeme Profile Picture
    355 on at

    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
    on at

    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?

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Varsha deshpande Profile Picture

Varsha deshpande 5

#2
NeerajPawar Profile Picture

NeerajPawar 2

#2
jlattimer Profile Picture

jlattimer 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans