web
You’re offline. This is a read only version of the page.
close
Skip to main content
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)
  • iyke Profile Picture
    5 on at
    RE: Custom ribbon enable rules aren't getting called

    Thanks, @Clofly, I feel so stupid!

  • iyke Profile Picture
    5 on at
    RE: Custom ribbon enable rules aren't getting called

    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";
    }

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Custom ribbon enable rules aren't getting called

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

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at
    RE: Custom ribbon enable rules aren't getting called

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

    Regards,

    Clofly

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at
    RE: Custom ribbon enable rules aren't getting called

    Hi,

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

    pastedimage1574331659596v1.png

    Regards,

    Clofly

  • iyke Profile Picture
    5 on at
    RE: Custom ribbon enable rules aren't getting called

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

  • iyke Profile Picture
    5 on at
    RE: Custom ribbon enable rules aren't getting called

    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.

  • cloflyMao Profile Picture
    25,210 on at
    RE: Custom ribbon enable rules aren't getting called

    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

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Custom ribbon enable rules aren't getting called

    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;
    }

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Sahan Hasitha Profile Picture

Sahan Hasitha 366

#2
Sohaib Cheema Profile Picture

Sohaib Cheema 106 User Group Leader

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 83 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans