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,...
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

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 March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 184 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 125

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans