Is it possible for the code below to send the boolean value from the inner function back to the parent function displayButton()? This parent function is triggered when a button in Dynamics CRM is clicked. The expected behavior is for the function to return a boolean value based on whether a case is selected and if that selected case is active or resolved.
//function called when a button in MS CRM is clicked
function displayButton()
{
var Obj = parent.Xrm.Page.getAttribute("regardingobjectid");
var ObjValue = Obj.getValue();
if (ObjValue == null)
return false;
var EntityType = ObjValue[0].entityType;
var Guid = ObjValue[0].id;
var id = Guid.slice(1, -1);
if (EntityType == "incident")
{
var req = new XMLHttpRequest();
req.open("GET", parent.Xrm.Page.context.getClientUrl() + "/api/data/v8.2/incidents(" + id + ")?$select=statecode", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function ()
{
if (this.readyState === 4)
{
req.onreadystatechange = null;
if (this.status === 200)
{
debugger;
var result = JSON.parse(this.response);
var statecode = result["statecode"];
var statecode_formatted = result["<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="abd8dfcadfcec8c4cfceebe4efcadfca85e8c4c6c6dec5c2dfd285efc2d8dbc7cad285fd9a85edc4d9c6cadfdfcecffdcac7dece">[email protected]</a>"];
if (statecode_formatted == "Active") {
return true;
}
else if (statecode_formatted == "Resolved")
return false;
else {
return false;
}
}
else
{
parent.Xrm.Utility.alertDialog("Zero");
}
}
};
req.send();
}
else {
return false;
}
}