Question Status

Verified
Don DeVeux asked a question on 24 Jan 2015 2:33 PM

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?

Reply
Suggested Answer
Guido Preite responded on 24 Jan 2015 2:36 PM

Hi,

the entity name to use in the function is "Incident", not "Case"

Reply
Don DeVeux responded on 24 Jan 2015 4:32 PM

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

Reply
Verified Answer
Chitrarasan Duraisamy responded on 24 Jan 2015 11:18 PM

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;
}

 

Chitra


Reply
Don DeVeux responded on 25 Jan 2015 8:35 AM

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.

Reply
John Leme responded on 29 Jan 2015 11:15 AM

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

Reply
Don DeVeux responded on 3 Feb 2015 5:22 PM

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?

Reply
Verified Answer
Chitrarasan Duraisamy responded on 24 Jan 2015 11:18 PM

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;
}

 

Chitra


Reply
Suggested Answer
Guido Preite responded on 24 Jan 2015 2:36 PM

Hi,

the entity name to use in the function is "Incident", not "Case"

Reply