Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Hiding button based on security roles from Home page in ribbon workbench using javasscript

(0) ShareShare
ReportReport
Posted on by 340

Hi Experts, 

I want to hide Assign button from contact using javascript and calling it to EnableRule and it works for form level button.

But when i try to hide for HomePage of contact to hide it from there also this JS doesn't work. we want to show it to admins only.

But it is not hiding for Home.

Please help me!

*This post is locked for comments

  • Suggested answer
    gdas Profile Picture
    50,089 Moderator on at
    RE: Hiding button based on security roles from Home page in ribbon workbench using javasscript

    Hi Alok,

    Please debug your code to make sure your code executing the return statement.

    You can also  try with below code-

    function HideAssignButton() {

    var result=false;

       var fetchCurrentRole = "<?xml version='1.0'?><fetch distinct='true' mapping='logical' output-format='xml-platform' version='1.0'><entity name='role'><attribute name='name'/><attribute name='roleid'/><order descending='false' attribute='name'/><link-entity name='systemuserroles' intersect='true' visible='false' to='roleid' from='roleid'><link-entity name='systemuser' to='systemuserid' from='systemuserid' alias='as'><filter type='and'><condition attribute='systemuserid' operator='eq-userid'/></filter></link-entity></link-entity></entity></fetch>";

       var SecurityRoles = XrmServiceToolkit.Soap.Fetch(fetchCurrentRole);  

       var rolearray=[];  

       if (SecurityRoles.length > 0) {        

           for (var i = 0; i < SecurityRoles.length; i++) {              

              rolearray[i] = SecurityRoles[i].attributes.name.value;

           }

           if ((rolearray.indexOf("System Administrator") != -1) || (rolearray.indexOf("IT System Admin Manager") != -1) || (rolearray.indexOf("HR System Admin") != -1)) {

               result= true;

           }

           else {

               result= false;

           }

       }

    return result;

    }

    In addition you could also check below my old post-

    [View:https://community.dynamics.com/crm/f/117/t/275058]

  • Arun Vinoth Profile Picture
    11,615 Moderator on at
    RE: Hiding button based on security roles from Home page in ribbon workbench using javasscript

    Did you debug? any error?

  • Alok Sharma Profile Picture
    340 on at
    RE: Hiding button based on security roles from Home page in ribbon workbench using javasscript

    Hi Arun,

    Thank you for your response !

    Using Security role I'm able to achieve my requirement and i did it already.

    But I wanted to do it from ribbon workbench which is not working , i called my enable rule for both plateform (form level and  Homepage level) and it is working for form level only not for homepage level.

    Here is my JS for this.

    function HideAssignButton() { 
        var fetchCurrentRole = "<?xml version='1.0'?><fetch distinct='true' mapping='logical' output-format='xml-platform' version='1.0'><entity name='role'><attribute name='name'/><attribute name='roleid'/><order descending='false' attribute='name'/><link-entity name='systemuserroles' intersect='true' visible='false' to='roleid' from='roleid'><link-entity name='systemuser' to='systemuserid' from='systemuserid' alias='as'><filter type='and'><condition attribute='systemuserid' operator='eq-userid'/></filter></link-entity></link-entity></entity></fetch>";
        var SecurityRoles = XrmServiceToolkit.Soap.Fetch(fetchCurrentRole);  
        var rolearray=[];   
        if (SecurityRoles.length > 0) {        
            for (var i = 0; i < SecurityRoles.length; i++) {               
               rolearray[i] = SecurityRoles[i].attributes.name.value;
            }
            if ((rolearray.indexOf("System Administrator") != -1) || (rolearray.indexOf("IT System Admin Manager") != -1) || (rolearray.indexOf("HR System Admin") != -1)) {
                return true;
            }
            else {
                return false;
            }
        }
    }


  • Verified answer
    Arun Vinoth Profile Picture
    11,615 Moderator on at
    RE: Hiding button based on security roles from Home page in ribbon workbench using javasscript

    For Home page & Entity form, there are 2 different ribbon/command bar and different Assign button available. Hope you added your Enable rule in both buttons.

    Another easy way is security role. Remove Assign privilege from non-admin user roles. This will hide them without any js code.

    If you still want to use script in Enable rule, sure the script & error if any.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,865 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,723 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans