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 :
Customer experience | Sales, Customer Insights,...
Unanswered

Add JS custom rule as Enable rule in ribbon

(0) ShareShare
ReportReport
Posted on by 458

Hi there All.
I want to add an Enable rule.

It is a custom rule via JS.
I have created a js web resource and place this function there :

function isInProgressOrRegistered() { 
	var userName=Xrm.Page.context.getUserName(); 
	if(userName=="Adam Smith")  { 
			return true;
	 } else  { 
			return false;
		}
}

Add this Library and function in Custom rule in Enable rules of RibbonWorkBench.

Here it is :

2783.community.JPG

But when publish the solution the button in the ribbon disappear or the js function does not work.
What I am Doing wrong?

Thanks

I have the same question (0)
  • MikeC282 Profile Picture
    2,175 on at

    Hi Albert,

    I suspect what is happening is that your rule is run asynchronously. Which means the page and command bar loads before the JS call has completed it's request for system user's name and hence defaulting to false.

    You'd need to fix this by adding a promise. Ajit wrote a good article on this (see below).

    ajitpatra.com/.../

    Kind regards,

    Mike

  • Pawar Pravin  Profile Picture
    5,237 on at

    Before making any changes I will suggest you to debug your code once.

    If its working in debug mode then change default value as true and invert result as false.

  • Albert_ Profile Picture
    458 on at

    I will try and let you know.

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans