Controlling visibility of a button based on a configuration setting
This is achievable using a built in javascript function in the sensei_SenseiProject.bundle.js.
sensei_SenseiProject.Generic.ConfigUtils.userHasSecurityRoleInConfig (
// “Configuration Setting Name” the is what is expected to be configured inside the environments configuration settings
configSettingName: string,
// “Path” – this should be path separated by “/” between elements within the above “Configuration Setting Name”
jsonPath: string,
// “Label” – this should be the name of the array that contains a list of User defined root roles
jsonLabel: string,
// “Key” – this should be the key value within an array which contains a list of User defined root roles
jsonKey: string,
// “Default roles” – If there is no configuration setting present and active in the environment then these comma separated root roles will be able to see the configured buttons
defaultValue: string
): Promise<boolean>
Below are some example uses of the function. Each example makes use of different parameters
Example use case - Show specific button based on user having security role/s in config
In order to conditionally show the "New" button if a user has permission to do so using a "configuration setting" to add new timesheets the following demonstration will illustrate how to configure ribbon workbench using XrmToolbox.
Install XrmToolbox

Open XrmToolbox
Create Connection to environment
In the bottom left corner create a new connection
- Click "Not connected"
- Click "Create new connection"

Make a new connection via the following:

Open the Login dialog box

Login to an "Office 365" tenant

- Select "Office 365"
- Toggle "Display list of available organizations"
- "Login"
Complete standard login and password with a minimum of system Customizer role to allow for editing of the ribbon.
Set the name it should be saved as:
- Recommend saving it under the tenant name
- Select finish to create connection

Now we need to connect to this created environment
- Click "Not connected" in the bottom left corner
- Expand "CM836721" in my example
- Click "Connect"

Opening "Ribbon Workbench"
- Click on "Tools"
- Click in search box area, Search for "Ribbon Workbench"
- Click on "Ribbon Workbench"
Using Ribbon Workbench to customize the environment
- Ribbon workbench allows for customization of upto 5 entities at one time. This is done by the following steps
- Create new solution or edit an existing solution with 5 or less entities in dynamics
- Add Existing entities you wish to customize by adding references only as shown below
- Click Entities in left hand side
- Click the "Add Existing" button

- Select solution components:
- Select the Entity you wish to customize. ie. Timesheet in our case
- Click "OK" to confirm

- Select Entity Assets to Include in the Solution:
- We want to uncheck "Include entity metadata"
- We want to select the "Main" form
- Click "Finish" to add it to the solution

- Select the solution which you wish to customize
- In this case we are using "RibbonWorkbench" solution
- Click on "OK" to load solution

- Ribbon workbench allows for customization of upto 5 entities at one time. This is done by the following steps
Now we need to customize the command associated with the buttons within Ribbon Workbench
- Select from the drop down menu “sensei_timesheet”
- Left click on “+New” in the ribbon
- You should see that the “Mscrm.HomepageGrid.sensei_timesheet.NewRecord” the key part is the “NewRecord” as there are two different ones under the “HomeGrid”
- Now Right click on that new button
- Select “Customize Command” this will populate the existing configuration for that button.

Repeat the above step 6 but for “SubGrid” and “Form”
- Confirm its correct button and customizing it
- Left click “New {0}” and confirm that it ends with “NewRecord” at arrow 3
- Right click the “New {0}” and Customize button
- Confirm its correct button and customizing it
- Left click “+New” and confirm that it ends with “NewRecord” at arrow 3
- Right click the “+New” button and Customize command
- This value will change depending on which of the buttons selected. Ie HomepageGrid, SubGrid, Form
- Look to see under “Enable Rules” – “sensei.sensei_timesheet.UserHasSecurityRoleInConfig.EnableRule” a. Click on this to edit the rules configuration in the next step – modifying this one value will adjust it for all three buttons as they all reference this “Enable Rule”

- Confirm its correct button and customizing it
Now we are going to go through how to customize the “Enable Rule”
- Left Click – sensei.sensei_timesheet.UserHasSecurityRoleInConfig.EnableRule
- Based on the settings you want to test adjust the following. “InvertResult” should be True or False(blank)
- “Configuration Setting Name” the is what is expected to be configured inside the environments configuration settings
- “Path” – this should be path separated by “/” between elements within the above “Configuration Setting Name”
- “Label” – this should be the name of the array that contains a list of User defined root roles
- “Key” – this should be the key value within an array which contains a list of User defined root roles
- “Default roles” – If there is no configuration setting present and active in the environment then these comma separated root roles will be able to see the configured buttons

For this example the following are values are used
Ribbon Workbench settings
{ "InvertResult": "False(blank)", "Configuration Setting Name": "timesheetConfiguration", "Path": "", "Label": "timesheetAddNewButtonRoles", "Key": "", "Default roles": "4c0f0c74-8b09-ea11-a811-000d3a530fe5" }Now once these are configured we need to publish the settings to the environment ~2-5 minutes at a time. It also is know to throw errors even though it has worked.
- Select “Publish” to apply the changes
Confirm dialog about making sure you back up your solution

- Select “Publish” to apply the changes
For the given configuration described above in part 9 we require a configuration setting called
timesheetConfigurationit can be configured by using the following JSON Schema and UI Schema. The JSON Schema is the actual configuration, UI Schema configures the entity lookup to allow for easy search for roles.
JSON Schema
{
"$schema": "http://json-schema.org/draft-07/schema",
"type": "object",
"title": "",
"properties": {
"timesheetAddNewButtonRoles": {
"$id": "#root/items/timesheetAddNewButtonRoles",
"title": "Security Roles that can see the New Timesheet button",
"description": "Note: Ensure all roles who require this access are added here. When no roles are provided, the default role/s configured will have access.",
"type": "array",
"default": [
"4c0f0c74-8b09-ea11-a811-000d3a530fe5"
],
"items": {
"$id": "#root/items/timesheetAddNewButtonRoles/items",
"title": "Security Role Id",
"description": "The role id as specified in Dynamics.",
"type": "string",
"default": "",
"pattern": "^.*$"
}
}
}
}
UI Schema
{
"timesheetAddNewButtonRoles": {
"ui:widget": "EntityLookupArrayWidget",
"ui:options": {
"endPoint": "roles",
"valueField": "_parentrootroleid_value",
"nameField": "name"
}
}
}
Example where path value is used
Ribbon Workbench settings
{
"InvertResult": "False(blank)",
"Configuration Setting Name": "simpleRoot",
"Path": "level/permissions",
"Label": "securityRoleIds",
"Key": "",
"Default roles": "4c0f0c74-8b09-ea11-a811-000d3a530fe5"
}
JSON Schema
{
"$schema": "http://json-schema.org/draft-06/schema#",
"title": "Entity Role Permissions",
"type": "object",
"properties": {
"level": {
"title": "Level",
"type": "object",
"properties": {
"permissions": {
"title": "Permissions",
"type": "object",
"properties": {
"securityRoleIds": {
"title": "Security Roles",
"type": "array",
"description": "If specified will only allow the people with the role(s).",
"items": {
"title": "Security Role",
"type": "string",
"format": "uuid"
}
},
"required": [
"securityRoleIds"
]
}
}
}
}
}
}
UI Schema
{
"level": {
"permissions": {
"securityRoleIds": {
"useArrayItemDialog": true,
"ui:widget": "EntityLookupArrayWidget",
"ui:options": {
"endPoint": "roles",
"valueField": "_parentrootroleid_value",
"nameField": "name"
}
}
}
}
}