Hello,
How to Show Subgrid Plus button only if user has Admin sec role otherwise need to hide. Need to javascript or can be done without code ?
*This post is locked for comments
Hello,
How to Show Subgrid Plus button only if user has Admin sec role otherwise need to hide. Need to javascript or can be done without code ?
*This post is locked for comments
@goutam
I have a similar requirement. Need to hide a subgrid add new option if lead status code is not equal to 100000002. Should I follow the same steps? And what would be JS code for it??
Thanks a lot gautam .
Hi Krishna,
Here is the detail step you need to follow , I have old code you can convert it to Web API call instead of organization service.
1) Import Ribbon workbench if you dont have it
2) Create one test solution and add your entity in the solution and javascript web resource with copying below code.
3) Go to the sub grid area , select Add New button , go to command section.
4) Add New Enable rule.
5) Select Default = false
6) Add Custome Javascript Rule
7) Provide function name SubgridButtonShowHide and web resource name.
8) Publish
function SubgridButtonShowHide() { var iSystemAdmin = false; var currentUserRoles = Xrm.Page.context.getUserRoles(); for (var i = 0; i < currentUserRoles.length; i++) { var userRoleId = currentUserRoles[i]; var userRoleName = GetRoleName(userRoleId); if (userRoleName == "System Administrator") { iSystemAdmin = true } } return iSystemAdmin; } function GetRoleName(roleId) { var serverUrl = Xrm.Page.context.getClientUrl(); var odataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc" + "/" + "RoleSet?$filter=RoleId eq guid'" + roleId + "'"; var roleName = null; $.ajax( { type: "GET", async: false, contentType: "application/json; charset=utf-8", datatype: "json", url: odataSelect, beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); }, success: function (data, textStatus, XmlHttpRequest) { roleName = data.d.results[0].Name; }, error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + textStatus + errorThrown + odataSelect); } } ); return roleName; }
Hope this helps.
Hi,
You can control through ribbon workbench. Go to ribbon workbench for that entity and add custom javascript enable rule , in the javascript function just check if security role = "System Administrator" then return true else return false.
Hope this helps.
Check below link,
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,235 Most Valuable Professional
nmaenpaa 101,156