SCRIPT1003: Expected ‘:’ Error in IE 11

Just sharing a simple scenario where my code was working in Chrome and Edge but It was throwing error  (SCRIPT1003: Expected ‘:’ ) in IE. Basically I was calling an Actions using Web API which was returning two output parameters then I was returning these two values to calling function.

mc.Ribbon.GetSignature = function () {
var signature;
var referenceno;
var Id = Xrm.Page.data.entity.getId().substring(1, 37);
var data = {
“receiptid”: Id
};
var clientURL = Xrm.Page.context.getClientUrl();
var req = new XMLHttpRequest();
req.open(“POST”, clientURL + “/api/data/v8.2/<entity>(” + Id + “)/Microsoft.Dynamics.CRM.<ActionName>”, false);
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 /* complete */) {
req.onreadystatechange = null;
if (this.status == 204 || this.status == 200) {
var receipts = JSON.parse(this.response);
signature = receipts[“signature”];
referenceno = receipts[“referenceno”];
}
else {
var error = JSON.parse(this.response).error;
}
}
};
req.send(JSON.stringify(data));
return {signature,referenceno};
};
Notice the return statement where I was returning two variable as object without key/value pair which was not working in IE 11 but it was working perfectly fine with Chrome and Edge. Then I changed the code to return array after assigning the value. See the correct code below which was working perfectly fine in IE 11 as well.

mc.Ribbon.GetSignature = function () {
var signArray = new Array();
var Id = Xrm.Page.data.entity.getId().substring(1, 37);
var data = {
“receiptid”: Id
};
var clientURL = Xrm.Page.context.getClientUrl();
var req = new XMLHttpRequest();
req.open(“POST”, clientURL + “/api/data/v8.2/<entity>(” + Id + “)/Microsoft.Dynamics.CRM.<ActionName>”, false);
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 /* complete */) {
req.onreadystatechange = null;
if (this.status == 204 || this.status == 200) {
var receipts = JSON.parse(this.response);
signArray[“signature”] = receipts[“signature”];
signArray[“referenceno”] = receipts[“referenceno”];
}
else {
var error = JSON.parse(this.response).error;
}
}
};
req.send(JSON.stringify(data));
return signArray;
};

Hope this helps.

Author: Arvind Singh

Microsoft Dynamics CRM Consultant

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s