Hi there All experts.
I have a JS Question.
I have a method in which I get State Code of SalesOrder entity.
Here is what I do :
function returnStateOfOrder() {
var orderStatusReasonId = Xrm.Page.getAttribute("xxxxxx").getValue()[0].id;
var trimedOrderStatusReasonId = orderStatusReason.replace('{', '').replace('}', '');
var stateCode;
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/SalesOrderSet(guid'" + trimedOrderStatusReasonId+ "')?$select=StateCode", false);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState === 4) {
this.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.responseText).d;
stateCode = result.StateCode.Value;
console.log("State code is : " + stateCode);
console.log(typeof(stateCode));
} else {
alert(this.statusText);
stateCode=-1;
}
}
return stateCode;
};
req.send();
}
It works Great,In the console It writes the state-code and type of it.
But in Another function that I call this method and assign the return value in this way :
switchCaseStateCode=returnStateOfOrder();
console.log(switchCaseStateCode);
But it display Undefined in the console !
I even changed the Asynchronous to false, But no success !
*This post is locked for comments
I have the same question (0)