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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Custom ribbon enable rules aren't getting called

(0) ShareShare
ReportReport
Posted on by 5

I am trying to show or hide a ribbon button using the following code:

jafgha.Activities.showButton = function (context)
{
console.log("testing validity**********");
const value = context.getAttribute("slakpistatus").getValue();
console.log(value);
return value === "2";
}

 pastedimage1574271180805v1.png

This does not work as the button is always displayed. Is there something I'm doing wrong?

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    getValue for optionset will return int so value === "2" will always return false. Try to use following:

    jafgha.Activities.showButton = function (context)
    {
        console.log("testing validity**********");
        const value = context.getAttribute("slakpistatus").getValue();
        console.log(value);
        return value === 2;
    }

  • cloflyMao Profile Picture
    25,210 on at

    Hi,

    Try to use ENABLE RULES and remove drop down value for both Default and invertResult:

    pastedimage1574318174046v1.png

    And change your code to below:

    jafgha.Activities.showButton = function(context) {
      console.log("testing validity**********");
      const value = context.getAttribute("slakpistatus").getValue();
      console.log(value);
      if (value == 2) {
        return true;
      } else {
        return false;
      }
    }

    Regards,

    Clofly

  • iyke Profile Picture
    5 on at

    slakpistatus is not an option set, it is a text field. And if you notice, I said the button is always displayed. If that expression always returns false, then the button should never be displayed. I think the problem is that the showButton function is never called, and I don't know why. I say that because the logs in this function do not appear in the console.

  • iyke Profile Picture
    5 on at

    I am using Enable Rules and I have tried your suggestions, it didn't work. Thanks for trying anyway.

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at

    Hi,

    Have you applied your rule to the button? (2)

    pastedimage1574331659596v1.png

    Regards,

    Clofly

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at

    If you didn't apply the rule(the function) to the button, then your function won't execute.

    Regards,

    Clofly

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Can you please provide the full code of your webresource or this is all that you have inside?

  • iyke Profile Picture
    5 on at

    Here's the entire file:

    if (typeof jafgha === 'undefined')
    {
    	jafgha = {};
    }
    if (!jafgha.Activities) jafgha.Activities = {};
    jafgha.Activities.showButton = function (context)
    {
    console.log("testing validity**********");
    const value = context.getAttribute("slakpistatus").getValue();
    console.log(value);
    return value === "2";
    }

  • iyke Profile Picture
    5 on at

    Thanks, @Clofly, I feel so stupid!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 74

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans