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?