Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Show Subgrid Plus button if user has Admin sec role

Posted on by 475

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

  • nidnani Profile Picture
    nidnani 285 on at
    RE: Show Subgrid Plus button if user has Admin sec role

    @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??

  • dkrishna Profile Picture
    dkrishna 475 on at
    RE: Show Subgrid Plus button if user has Admin sec role

    Thanks a lot gautam .

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Show Subgrid Plus button if user has Admin sec role

    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.

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Show Subgrid Plus button if user has Admin sec role

    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.

  • Verified answer
    Shahbaaz Ansari Profile Picture
    Shahbaaz Ansari 6,203 on at
    RE: Show Subgrid Plus button if user has Admin sec role

    Check below link,

    community.dynamics.com/.../227763

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans