Show/Hide Buttons Based on Entity Permissions Using Power FX

Sending
User Review
0 (0 votes)

Entity Permissions Using Power FX

Recently, we received a client requirement to show a button to users who have the Create permission for a specific entity. In the traditional approach, we would use the Ribbon Workbench in XrmToolBox to add buttons and write JavaScript code to check user permissions. While this method works fine, it can be a bit complex and technical.

After doing some research and exploring Microsoft Docs, we found a Power Fx formula:

DataSourceInfo({EntityName},DataSourceInfo.{Permission})

This formula checks the Table (Entity) permission. By using the Power Fx formula, we can easily control the visibility of the button based on permissions. This method is much simpler.

How to Implement This in Dynamics 365

1. Create a New Button: Using the Command Bar Editor in Dynamics 365, create a new button that we need to hide or show based on privileges.

For more detailed guidance, refer to the Customize the command bar using command designer.

2. Set Button Properties: In the properties of the newly created button, go to the Visibility section and select “Show on Condition from Formula.

Entity Permissions Using Power FX 1

3. Add the Formula: For example, if we want to show a button only if the user has Create permission for the Account entity, we use the DataSourceInfo function with Create Permissions in the Power FX formula.

Entity Permissions Using Power FX 1

Fx Formula: If((DataSourceInfo(Accounts,DataSourceInfo.CreatePermission)), true, false)

For more information about DataSourceInfo, you can check for other permissions such as:

Entity Permissions Using Power FX 1

Like DataSourceInfo, there is another method called RecordInfo that controls button visibility based on permissions related to individual records. While DataSourceInfo checks permissions at the entity wise, RecordInfo checks privileges for a specific record within that entity.

For example, if you want to display a button only when the user has edit permissions on a selected record in Main Grid, use the following Power FX formula:

Entity Permissions Using Power FX 1

Fx Formula: If(RecordInfo(Self.Selected.Item, RecordInfo.EditPermission),true, false)

Conclusion :

The old approach of using the XrmToolBox Ribbon Workbench is functional but complex and time-consuming. To simplify this, we can use the Power FX DataSourceInfo function, which achieves the same result in less time and makes the process simpler.

Alerts4Dynamics

The post Show/Hide Buttons Based on Entity Permissions Using Power FX first appeared on Microsoft Dynamics 365 CRM Tips and Tricks.