Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Dynamically hide or show ribbon button based on regarding field in Email Entity.

Posted on by Microsoft Employee

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

  • RE: Dynamically hide or show ribbon button based on regarding field in Email Entity.

    Try to debug the code and check accordingly  

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans