Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Using Sales Manager Role "Email a Link" feature must be disable

Posted on by 340

Hi All,

We have a requirement that using Sales Managers Role , when we click on "Email a Link" button then some error thrown. Means using sales manager role this button should not work. 

Can we do it using Security Role .

Thanks in Advance.

*This post is locked for comments

  • Verified answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Using Sales Manager Role "Email a Link" feature must be disable

    Hi Nilanka,

    You can customize the Email a Link button and add a new Enable Rule in Ribbon Workbench.

    Select Custom Rule and give the following Javascript web resource with the function getUserRoles.

    // JavaScript source code
    function getUserRoles() {
        var roles = Xrm.Page.context.getUserRoles();
        var roleName;
        for (var i = 0; i < roles.length; i++) {
            var roleID = roles[i];
            var RoleName = getRoleName(roleID);
            if (RoleName == 'Sales Manager') {
                return false;
            }
            else {
                return true;
            }
        }
    }
    function getRoleName(roleID) {
        var clientURL = Xrm.Page.context.getClientUrl();
        var req = new XMLHttpRequest();
        var query = "/api/data/v8.2/roles/?$top=1&$select=name&$filter=roleid eq " + roleID;
        req.open("GET", encodeURI(clientURL + query), true);
        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) {
                req.onreadystatechange = null;
                if (this.status == 200) {
                    var data = JSON.parse(this.response);
                    if (data && data.value) {
                        for (var indx = 0; indx < data.value.length; indx++) {
                            var roleName = data.value[indx].name;
                        }
                    }
                }
                else {
                    var error = JSON.parse(this.response).error;
                    alert("Error retrieving Roles – " + error.message);
                }
            }
        };
        req.send(null);
    }

    Hope this helps.

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,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans