web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Hide and Show button based on Database value

(0) ShareShare
ReportReport
Posted on by 5

pastedimage1626405839182v2.png

pastedimage1626405900862v3.png

Hi, 

I need to hide and show assign button on the case entity, if the value of stage from the other entity (hide and show button) is equal to the stage of case entity using js.

I have also written a code, it gives me  an alert when stages of both entity is equal but doesn't hide and show button using return true or false.

Any kind of help will be appreciated.

function Can(PrimaryControl)
{
debugger;
var formContext = PrimaryControl;
var stage=formContext.getAttribute("ss_stage").getValue();
var status=formContext.getAttribute("ss_casestatus").getValue();
if(stage!=null)
{
Xrm.WebApi.online.retrieveMultipleRecords("ss_showhidebutton", "?$select=ss_buttonname,ss_role,ss_showhidebuttonid,ss_stage,ss_status").then(
function success(results) {
for (var i = 0; i < results.entities.length; i++) {
var ss_buttonname = results.entities[i]["ss_buttonname"];
var ss_role = results.entities[i]["ss_role"];
var ss_role_formatted = results.entities[i]["ss_role@OData.Community.Display.V1.FormattedValue"];
var ss_showhidebuttonid = results.entities[i]["ss_showhidebuttonid"];
var ss_stage = results.entities[i]["ss_stage"];
var ss_stage_formatted = results.entities[i]["ss_stage@OData.Community.Display.V1.FormattedValue"];
var ss_status = results.entities[i]["ss_status"];
var ss_status_formatted = results.entities[i]["ss_status@OData.Community.Display.V1.FormattedValue"];
if(stage==ss_stage)
{
return true;
}
}
},
function(error) {
Xrm.Utility.alertDialog(error.message);
}
);
else
{
return false;
}
}

I have the same question (0)
  • Verified answer
    meelamri Profile Picture
    13,218 User Group Leader on at

    Hi Shoaib,

    Enablerules are synchronous, and your code is asynchronous, that's why your button doesn't react to the return of your function.

    This problem is well known in our community. Andrew wrote a blog about this... You can refer to his code to correct yours: butenko.pro/.../

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 81 Super User 2026 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#3
11manish Profile Picture

11manish 62

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans