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
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?
You must update your sdk.rest.js file. Download the latest sdk and update. The difference is that getServerUrl() has been replaced by getClientUrl().
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.
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;
}
Yeah - sorry, I tried that too. Forgot to change this message to the current version of the code.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,134 Super User 2024 Season 2
Martin Dráb 229,928 Most Valuable Professional
nmaenpaa 101,156