Hi,
I created a button in Email entity(using ribbon workbench) and I want it to be displayed only if a Case is selected in regarding field. Also, the selected case should be active. If it is not active, the button should not be displayed. The below code works by hiding the button when I select any other entity than case. But the button is being displayed even if the Case is not active. How can I make it hide if the case is resolved and display if the case is active? Below is the code:
// called on click of a button in CRM.
function displayButton() {
var regarding = parent.Xrm.Page.getAttribute("regardingobjectid").getValue();
var entityType = regarding[0].entityType;
var regardingId = regarding[0].id.slice(1, -1);
// Check if regarding is an active case.
if (entityType == "incident") {
getCaseState(regardingId, function (state) {
alert(state);
isActive= state === "Active";
return isActive;
});
}
else
return false;
}
function getCaseState(id, callback) {
debugger;
var req = new XMLHttpRequest();
req.open("GET", parent.Xrm.Page.context.getClientUrl() + "/api/data/v8.2/incidents(" + id + ")?$select=statecode", false);
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) {
var result = JSON.parse(this.response);
var statecode = result["statecode"];
var statecode_formatted = result["statecode@OData.Community.Display.V1.FormattedValue"];
callback(statecode_formatted);
}
}
};
req.send();
}
displayButton is the function called from enableRule in ribbon workbench.
*This post is locked for comments