locked
Show/Hide Advance Find Button based on users RRS feed

  • Question

  • Hi,

    I am using CRM-2011 On Premises and want to hide Advance Find button for some users.

    If anyone have an idea please share with me.

    thanks in advance.

    Friday, November 21, 2014 4:11 PM

All replies

  • Riaz,

    Check this http://www.dynamicscrmguide.com/this-is-a-test-post/

    HTH


    If my response helps you in finding your answer then please click 'Mark as Answer' and 'Vote as Helpful'

    • Proposed as answer by Mamatha Swamy Friday, November 21, 2014 8:00 PM
    Friday, November 21, 2014 8:00 PM
  • I'd recommend using the Ribbon Workbench to setup a display rule. If you cannot work out the logic within various rules like a value rule or a EntityPrivilegeRule, you can setup a custom rule and code your rule using JavaScript .  You can use an existing user role or create one just for this.  So say you create a user role called "Hide Advanced Find Button", then assign all of the users that you want to hide the button for.  Or you could reverse it and setup a role for all of the users that you want to view the button, but I suspect there's more users with access than there are that you want to remove it from. Also, if you have some other role you can use for this, say a user is in the admin role or some other existing role, use that one.  If not, just create it.

    Then in the ribbon setup a display rule and a CustomRule, then create a JavaScript function to be executed from your CustomRule that will return a Boolean to indicate when the button should be displayed. Here's how I would setup the CustomRule .

    • Default: True
    • FunctionName: UserHasAdvancedFindAccess
    • InvertResult: False
    • Libray:   $webresource:CustomJavaScriptLibrary

    Here's a sample I worked out from various online forums and samples when trying to do something similar for my project.

    function UserHasAdvancedFindAccess() {
        if (UserHasRole("System Administrator")) 
            return true;
        else 
            if (UserHasRole("Hide Advanced Find Button"))
                return true;
        return false;
    }
    
    function UserHasRole(roleName) {
        var serverUrl = Xrm.Page.context.getServerUrl();
        var oDataEndpointUrl = serverUrl + "/XRMServices/2011/OrganizationData.svc/";
        oDataEndpointUrl += "RoleSet?$top=50&$filter=Name eq '" + roleName + "'";
        var service = GetRequestObject();
        if (service != null) {
            service.open("GET", oDataEndpointUrl, false);
            service.setRequestHeader("X-Requested-Width", "XMLHttpRequest");
            service.setRequestHeader("Accept", "application/json, text/javascript, */*");
            service.send(null);
            var requestResults = eval('(' + service.responseText + ')').d;
            if (requestResults != null && requestResults.results.length > 0) {
                for (var x = 0; x < requestResults.results.length; x++) { // Loop through each CRM role.
                    var role = requestResults.results[x];
                    var id = role.RoleId;
                    var currentUserRoles = Xrm.Page.context.getUserRoles();
                    for (var i = 0; i < currentUserRoles.length; i++) {
                        var userRole = currentUserRoles[i];
                        if (GuidsAreEqual(userRole, id)) {
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }
    
    function GetRequestObject() {
        if (window.XMLHttpRequest) {
            return new window.XMLHttpRequest;
        }
        else {
            try {
                return new ActiveXObject("MSXML2.XMLHTTP.3.0");
            }
            catch (ex) {
                return null;
            }
        }
    }
    
    function GuidsAreEqual(guid1, guid2) {
        var isEqual = false;
        if (guid1 == null || guid2 == null) {
            isEqual = false;
        }
        else {
            isEqual = guid1.replace(/[{}]/g, "").toLowerCase() == guid2.replace(/[{}]/g, "").toLowerCase();
        }
        return isEqual;
    }


    Jon Gregory Rothlander




    Friday, November 21, 2014 9:22 PM