Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

CRM 365: JavaScript - Error while retrieving parent entity data

$
0
0

Hi

In a CRM Case record I am trying to retrieve information from Account entity. Below is the code I have written but it throws the below error when I debug.

Can anyone help me please?

SCRIPT1014: Invalid character  at JSON.Parse(this.response)

var oAccount = Xrm.Page.data.entity.attributes.get('dcit_accountid');

if(oAccount.getValue()[0] != null)
{
oAccountId = oAccount.getValue()[0].id.replace(/\{|\}/gi,""); //To remove the braces at start and end of GUID
var clientURL = Xrm.Page.context.getClientUrl();
var req = new XMLHttpRequest();
var query = "/api/data/v8.2/accounts?$filter= accountid eq " +""+ oAccountId;
//var query = "/api/data/v8.2/accounts?$filter= AccountId eq guid'"+oAccount.getValue()[0].id+"'";
req.open("GET", encodeURI(clientURL + query), true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if (this.readyState == 4) {
req.onreadystatechange = null;
if (this.status == 200)
{
JSON.parse(this.response);
}
else {
var error = JSON.parse(this.response).error;
alert("Error retrieving Record – " + error.message);
}
}
};
req.send();
}


Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images