I have a Dynamics 365 v9.x environment and I need to prevent everyone from using the bulk edit feature on a specific entity unless they are a member of a specific security group. Bulk edit on all other entities needs to run normally.
I can already hide and show buttons this way, but I do not want to hide the edit button unless users have multiple records selected, which would normally cause the edit button to open a "bulk edit" screen.
I have the Ribbon Workbench installed and I created an Enable Rule.
I also created a Display Rule as shown below.
I can show and hide the button based on the security role per the JavaScript shown below. The way the rule is set, it hides the edit button for everyone except the people who are members of Security Role A.
function ShowHideEditBtnBasedOnSecurityRole() { var roles = []; roles[0] = "Security Role A"; // roles[1] = "System Administrator"; var IsUserMemberOfRDR = currentUserHasSecurityRole(roles); function currentUserHasSecurityRole(roles) { var fetchXml = "<fetch mapping='logical'>" + "<entity name='systemuser'>" + "<attribute name='systemuserid' />" + "<filter type='and'>" + "<condition attribute='systemuserid' operator='eq-userid' />" + "</filter>" + "<link-entity name='systemuserroles' from='systemuserid' to='systemuserid' visible='false' intersect='true'>" + "<link-entity name='role' from='roleid' to='roleid' alias='r'>" + "<filter type='or'>"; for (var i = 0; i < roles.length; i++) { fetchXml += "<condition attribute='name' operator='eq' value='" + roles[i] + "' />"; } fetchXml += " </filter>" + "</link-entity>" + "</link-entity>" + "</entity>" + "</fetch>"; var modifiedFetchXml = fetchXml.replace("&", "&"); var users = ExecuteFetch(modifiedFetchXml, "systemusers"); if (users > 0) return true; else return false; } function ExecuteFetch(originalFetch, entityname) { var count = 0; var fetch = encodeURI(originalFetch); var globalContext = Xrm.Utility.getGlobalContext(); var userId = globalContext.userSettings.userId; var serverURL = globalContext.getClientUrl(); var Query = entityname + "?fetchXml=" + fetch; var req = new XMLHttpRequest(); req.open("GET", serverURL + "/api/data/v9.0/" + Query, false); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.onreadystatechange = function () { if (this.readyState == 4 /* complete */) { req.onreadystatechange = null; if (this.status == 200) { var data = JSON.parse(this.response); if (data != null) { count = data.value.length; } } else { var error = JSON.parse(this.response).error; alert(error.message); } } }; req.send(); return count; }; if (IsUserMemberOfRDR === true) { return true; } else { return false; } }
However, this is not exactly what I need to do.
I need to prevent the Edit Button from working or displaying ONLY when multiple records are selected or prevent the bulk edit privilege from working for anyone who is not a member of Security Role A.
What exactly do I need to do with the Display Rule or from within the ribbon workbench to achieve this result?
Thanks for the recommendation. I found this which clearly and directly explains how to create and apply a selection count rule using ribbon workbench. ankit.inkeysolutions.com/.../selection-count-rule-display-ribbon.html
Now the only thing left to do is to figure out how to "make this selection count rule" only go into effect if the user is not in my specified security group.
How can I "put something together" in ribbon workbench that will only apply this rule use this rule if the user is not in my specified security group?
If someone can post a screen shot that shows the specifics of what must be done in ribbon workbench to make the selection rule be dependent on an a false being returned from a custom enable rule, that would solve my problem.
You can add a SelectionCountRule (msdn.microsoft.com/.../gg309316.aspx).
On a side note, checking the security roles in JavaScript will require synchronous Web API calls, which can significantly increase the load time. I usually ballpark it at .5 seconds for each synchronous call. But if you have this rule on 10 buttons, that will add about 5 seconds to the load time. If you're on a bad connection, it will be torture.
As an alternative, I would recommend adding an OTB privilege rule tied to a privilege which is exclusive to the security roles you are targeting (msdn.microsoft.com/.../gg334239.aspx).