Microsoft Power Platform - Show/hide ribbon buttons on field values & roles
Author: Praful Shelke

Microsoft Power Platform - Show/hide ribbon buttons on field values & roles

Team Stralto implemented ribbon customization per business requirement where expectation was to show or hide of custom buttons on ribbon based on value of a particular field and/or for a certain security role of the user.??

We did find similar open questions on stack overflow and other dynamics/power apps forums but were unable to search a decent workable solution. This endeavor made us include the use case in our tech. blog and it is written with an intent to assist development community.

Developers can quickly achieve this type of customization activity in model driven apps with JavaScript. Sample with code snippet:?

function showAcceptButton(primaryControl) {
	
		globalFormContext = primaryControl;

		var value = globalFormContext.getAttribute('ex_paymentstatus').getValue();

		var roleIsMatchingFlag = false;
		//  debugger;
		var currentUserRoles = Xrm.Page.context.getUserRoles();
		for (var i = 0; i < currentUserRoles.length; i++) {
			var userRoleId = currentUserRoles[i];
			var userRoleName = GetRoleName(userRoleId);
			if (value == 111111111 && ((userRoleName === "System Administrator")) {
				roleIsMatchingFlag = true;
				break;
			}
		}
		return roleIsMatchingFlag;
	}
}        

The ribbon button “Accept” should be visible to only when the value in the “Payment Status” field is “Completed” and for users with the “System Administrator” role.?

Note: Here, the value '111111111' represents the status 'Completed'.?

The above JavaScript function checks for all the roles user has; if the desired security role is found, it will return the value 'True'. It will also check for the Payment status and if the value matches, it will return True and show or hide the button.?

?Reach out to [email protected] or [email protected] for more details.

Vrushabh Rewatkar

Jr. Software Engineer at Technomile

2 年

Congratulations Praful Shelke

Excellent work ??

Shashikesh Naokar

DevOps Engineer at Lentra

2 年

Congratulations?? bro??

Ashish M.

Microsoft Dynamics 365 CRM Developer | 3+ Years of Expertise in Customization, Configuration & Integration | Passionate About Automating Workflows Enhancing Customer Engagement & Driving Digital Transformation for Growth

2 年

Great job Praful Shelke .... Kudos to Stralto Global for this initiative....??????

Rajesh Turerao

Consultant at Stralto

2 年

Congratulations Praful..keep up the good work.

要查看或添加评论,请登录

Stralto Global的更多文章

社区洞察

其他会员也浏览了