Hello All,
I am stuck with a situation. I am trying to make a button visible on the flyout menu on the form ribbon based on an enable rule. The enable rule has a javascript, which performs an xmlhttprequest to get a related record, if there are no realted records i want to show the button and if there are then i want to hide it.
When i debugged the javascript it seems to be working but the button's visibility is not changing based on the return value from the javascript.
i am doing this on CRM 365 On-Premise
Here is my code:
function checkRelatedRecords()
{
debugger;
var userId = Xrm.Page.context.getUserId();
userId=userId.replace("{","").replace("}","");
var recId = Xrm.Page.data.entity.getId();
recId=recId.replace("{","").replace("}","");
var recType = Xrm.Page.data.entity.getEntityName();
var filterExpression="_new_followedby_value eq " +userId + " and _new_following" + recType + "_value eq " + recId;
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/new_followemails?$filter="+filterExpression, 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) {
var results = JSON.parse(this.response);
if(results.value.length > 0)
{
return false;
}
else
{
return true;
}
}else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
*This post is locked for comments
I have the same question (0)