2
votes

I've modified the sitemap of a CRM 2011 solution to contain a new Area. That area contians a single Group and the Group contains a single SubArea.

The SubArea is defined with a URL attribute similar to this...

<SubArea Id="x" Url="/WebResources/new_/y.html"
            <Titles>
              <Title Title="z" LCID="1033" />
            </Titles>
</SubArea>

When a user clicks on this subarea in the nav bar the y.html webresource loads in the content area of CRM as expected. It loads similar to how a grid view would load, but instead of the grid view, y.html is loaded.

In addition, a customized ribbon is loaded.

Currently this customized ribbon disables ribbon button groups based on the role of the current user. This is done using an EnableRule of the CommandDefinition in RibbonDiffXml. In the EnableRule a CustomRule is defined that references a javascript function that returns true or false based on some custom logic regarding the users role.

This is working well. However, I've been asked to remove the ribbon button groups instead of just hiding them.

My understanding is that this is more of a task for a DisplayRule than an enable rule. However, from what I gather DisplayRule does not have a CustomRule option as EnableRule does.

After gathering that DisplayRule isn't an option, I thought that I might be able to write some javascript in the Enable rule to remove the group (as well as return a value to enable it or not). However, after debugging the javascript, I see that although I have access to Xrm.Page, I do not have access to Xrm.Page.ui (similar to the expected result for a grid view). Therefore, I can't disable the tab here either (without resorting to unsupported javascript).

How can I use custom logic to conditionally display a ribbon group in a grid view-like scenario in a supported fashion (e.g. no jQuery/ect)?

1
+1, hope someone can answer affirmatively to this. But the tabs collection in Xrm.Page.ui refers to the navigation in the main part of an entity form, so you wouldn't be able to change the ribbon that way either. The best you can do with Xrm.Page is call the refreshRibbon method, but that wouldn't affect the visibility of the ribbons anyway.Peter Majeed

1 Answers

0
votes

Currently this customized ribbon disables ribbon button groups based on the role of the current user...

I assume then that you basically wish to toggle ribbon functionality, based on user's permissions.

DisplayRule does not have a CustomRule option as EnableRule does...

Correct

DisplayRule isn't an option

Not sure that this is necessarily true. While DisplayRule may not have a CustomRule option, it does have a MiscellaneousPrivilegeRule.

Depending on the configuration of your roles and your requirements, you may be able to bypass looking at the users "role" and instead set up a rule that effectively checks: if the user can read the invoice entity, show this button (group) (obviously this is just an example - you get the idea)...

If your roles are more complex you could create a pseudo-entity (e.g. called "CanViewMySpecialButtons"), remove it from anywhere in the UI and only grant read permissions to the roles that should view your buttons. You can then create a MiscellaneousPrivilegeRule that checks if the user can read your pseudo-entity - only those users in your role are able to see that entity therefore the button can be set hidden for all other users.