
I am trying to make an Ajax call from MSCRM (My CRM Deployment is with Update Roll up 14 on OS SQL Server 2012). My function reaches in "I am Success" alert but than on next alert I receive error
--------------------------- Message from webpage ---------------------------
An error has occurred.
Try this action again. If the problem continues, check the Microsoft Dynamics CRM Community for solutions or contact your organization's Microsoft Dynamics CRM Administrator. Finally, you can contact Microsoft Support.
--------------------------- OK ---------------------------
Following is my code:
function retrieveSelectedRecord(accountId) {
var select = "&select=Name,accountId";
var filter = "&filter=AccountId eq guid'" + accountId + "'";
var oDataSelect;
oDataSelect = "/XRMServices/2011/OrganizationData.svc/AccountSet?" + select + filter;
jQuery.support.cors = true;
$.support.cors = true;
$.ajax({ type: "GET",
contentType: "application/json;
charset=utf-8", datatype: "json",
url: oDataSelect, beforeSend:
function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function (data, textStatus, XmlHttpRequest)
{ // Use for a single selected entity
alert("I am in Success");
alert(data); ProcessReturnMsg(data.d); },
error: function (xmlHttpRequest, textStatus, errorThrown)
{
alert("I am in Error");
alert("Status: " + textStatus + "; ErrorThrown: " + errorThrown); }
});
}
function ProcessReturnMsg(entity) {
var name = entity.Name;
alert(name);
//Xrm.Page.getAttribute("uomid").setValue(defaultuomid);
}
*This post is locked for comments
I have the same question (0)I assume your error might have been coming when trying to display the record Name???
The OData query you have is essentially could retrieve multiple records since you are using a filter condition (even though you are filtering by the unique id).
So when processing the resulting data - you would need something like:
var name = entity.results[0].Name;
Also in your select, you should have "AccountId" -to match the correct schema name of the field.
If you only want to select a single record by unique id, your OData query should look like:
"/XRMServices/2011/OrganizationData.svc/AccountSet(guid'" + accountId+ "')?$select=Name";
Then you should not end up with the .results collection attached to the returned object.