locked
Can I hide a tab from specific users in CRM? RRS feed

  • Question

  • I have created a form (tab) in the Quotes entity.  I would like to hide it from my sales staff so only the CEO can see it.  Is there any way to do this in CRM?  Thanks in advance!  Bill

    Monday, February 4, 2008 3:34 PM

Answers

  • Add this to the onload event

     

    crmForm.all.tab1Tab.style.display = "none";

     

    tab0Tab - first tab

    tab1Tab - second tab etc.

     

    You'll need to use client side code (see the SDK's whoami example) to detect the CEO's guid. 

     

    The use IF condition to call the above code.

     

    If you need help feel free to contact me I'm open for assistance.

     

    Michael Ferreira

     

    www.michaelferreira.ca

     

    Monday, February 4, 2008 4:22 PM
  • I do agree with Michael, you need javascript validation base on user who is login and then hide fields or tabs base on role.

     

    Here is code snipt for your info

     

    This solution is very neat and very clean, though unsupported!!! Now... Let's get started and dig into this.

    MS CRM has a lot of Javascript codes delivered with the product. One of these codes is located here: "/_controls/RemoteCommands/RemoteCommand.js". This file is being included into every page. One of the functions in this file is RemoteCommand(sObject, sCommand, sUrlBase). You can use this function to connect to CRM webservices.

    Via Javascript you can get the userid of the currently logged in user via this RemoteCommand. This is done using this code:


    var command = new RemoteCommand("SystemUser", "WhoAmI", "/MSCRMServices/");
    var oResult = command.Execute();



    Another webservice which is interesting is the UserManager webservice. By using this function, you can get all roles of the system. The roles to which the user is assigned are marked with "checked='true'". Here's the code to get this list


    var command = new RemoteCommand("UserManager", "GetUserRoles");
    command.SetParameter("userIds", "<guid>" + userId + "</guid>");
    var oResult = command.Execute();



    Now if we add this functionality to functions and add some try catches, then you'll end up with this code:


    function getUserId()
    {
    try
    {
    var command = new RemoteCommand("SystemUser", "WhoAmI", "/MSCRMServices/");
    var oResult = command.Execute();

    if (oResult.Success)
    {
    return oResult.ReturnValue.UserId;
    }
    }
    catch(e)
    {
    alert("Error while retrieving userid.");
    }
    return null;
    }

    function getUserRoles(userId)
    {
    try
    {
    var command = new RemoteCommand("UserManager", "GetUserRoles");
    command.SetParameter("userIds", "<guid>" + userId + "</guid>");

    var oResult = command.Execute();

    if (oResult.Success)
    {
    return oResult.ReturnValue;
    }
    }
    catch(e)
    {
    alert("Error while retrieving roles.");
    }
    return null;
    }



    Now we only have to add functions which checks if the user has a specific role. The final code is:


    function getUserId()
    {
    try
    {
    var command = new RemoteCommand("SystemUser", "WhoAmI", "/MSCRMServices/");
    var oResult = command.Execute();

    if (oResult.Success)
    {
    return oResult.ReturnValue.UserId;
    }
    }
    catch(e)
    {
    alert("Error while retrieving userid.");
    }
    return null;
    }

    function getUserRoles(userId)
    {
    try
    {
    var command = new RemoteCommand("UserManager", "GetUserRoles");
    command.SetParameter("userIds", "<guid>" + userId + "</guid>");

    var oResult = command.Execute();

    if (oResult.Success)
    {
    return oResult.ReturnValue;
    }
    }
    catch(e)
    {
    alert("Error while retrieving roles.");
    }
    return null;
    }

    function userHasRole(userId, roleName)
    {
    result = getUserRoles(userId);
    if (result != null)
    {
    var oXml = new ActiveXObject("Microsoft.XMLDOM");
    oXml.resolveExternals = false;
    oXml.async = false;
    oXml.loadXML(result);

    roleNode = oXml.selectSingleNode("/roles/role[name='" + roleName + "']");
    if (roleNode != null)
    {
    if (roleNode.selectSingleNode("roleid[@checked='true']") != null)
    return true;
    }
    }

    return false;
    }

    function currentUserHasRole(roleName)
    {
    userId = getUserId();
    return userHasRole(userId, roleName);
    }



    Now you can check for roles by using the code listed down here:


    if(currentUserHasRole('CEO')){
    alert('true');
    }else{
    alert('false');
    }



    You can copy and paste the functions as well as the last code in the form onload event.

     

    Best Regards,

    Imran

     

    http://microsoftcrm3.blogspot.com

     

    Tuesday, February 5, 2008 3:39 AM
    Moderator

All replies

  • Add this to the onload event

     

    crmForm.all.tab1Tab.style.display = "none";

     

    tab0Tab - first tab

    tab1Tab - second tab etc.

     

    You'll need to use client side code (see the SDK's whoami example) to detect the CEO's guid. 

     

    The use IF condition to call the above code.

     

    If you need help feel free to contact me I'm open for assistance.

     

    Michael Ferreira

     

    www.michaelferreira.ca

     

    Monday, February 4, 2008 4:22 PM
  • I do agree with Michael, you need javascript validation base on user who is login and then hide fields or tabs base on role.

     

    Here is code snipt for your info

     

    This solution is very neat and very clean, though unsupported!!! Now... Let's get started and dig into this.

    MS CRM has a lot of Javascript codes delivered with the product. One of these codes is located here: "/_controls/RemoteCommands/RemoteCommand.js". This file is being included into every page. One of the functions in this file is RemoteCommand(sObject, sCommand, sUrlBase). You can use this function to connect to CRM webservices.

    Via Javascript you can get the userid of the currently logged in user via this RemoteCommand. This is done using this code:


    var command = new RemoteCommand("SystemUser", "WhoAmI", "/MSCRMServices/");
    var oResult = command.Execute();



    Another webservice which is interesting is the UserManager webservice. By using this function, you can get all roles of the system. The roles to which the user is assigned are marked with "checked='true'". Here's the code to get this list


    var command = new RemoteCommand("UserManager", "GetUserRoles");
    command.SetParameter("userIds", "<guid>" + userId + "</guid>");
    var oResult = command.Execute();



    Now if we add this functionality to functions and add some try catches, then you'll end up with this code:


    function getUserId()
    {
    try
    {
    var command = new RemoteCommand("SystemUser", "WhoAmI", "/MSCRMServices/");
    var oResult = command.Execute();

    if (oResult.Success)
    {
    return oResult.ReturnValue.UserId;
    }
    }
    catch(e)
    {
    alert("Error while retrieving userid.");
    }
    return null;
    }

    function getUserRoles(userId)
    {
    try
    {
    var command = new RemoteCommand("UserManager", "GetUserRoles");
    command.SetParameter("userIds", "<guid>" + userId + "</guid>");

    var oResult = command.Execute();

    if (oResult.Success)
    {
    return oResult.ReturnValue;
    }
    }
    catch(e)
    {
    alert("Error while retrieving roles.");
    }
    return null;
    }



    Now we only have to add functions which checks if the user has a specific role. The final code is:


    function getUserId()
    {
    try
    {
    var command = new RemoteCommand("SystemUser", "WhoAmI", "/MSCRMServices/");
    var oResult = command.Execute();

    if (oResult.Success)
    {
    return oResult.ReturnValue.UserId;
    }
    }
    catch(e)
    {
    alert("Error while retrieving userid.");
    }
    return null;
    }

    function getUserRoles(userId)
    {
    try
    {
    var command = new RemoteCommand("UserManager", "GetUserRoles");
    command.SetParameter("userIds", "<guid>" + userId + "</guid>");

    var oResult = command.Execute();

    if (oResult.Success)
    {
    return oResult.ReturnValue;
    }
    }
    catch(e)
    {
    alert("Error while retrieving roles.");
    }
    return null;
    }

    function userHasRole(userId, roleName)
    {
    result = getUserRoles(userId);
    if (result != null)
    {
    var oXml = new ActiveXObject("Microsoft.XMLDOM");
    oXml.resolveExternals = false;
    oXml.async = false;
    oXml.loadXML(result);

    roleNode = oXml.selectSingleNode("/roles/role[name='" + roleName + "']");
    if (roleNode != null)
    {
    if (roleNode.selectSingleNode("roleid[@checked='true']") != null)
    return true;
    }
    }

    return false;
    }

    function currentUserHasRole(roleName)
    {
    userId = getUserId();
    return userHasRole(userId, roleName);
    }



    Now you can check for roles by using the code listed down here:


    if(currentUserHasRole('CEO')){
    alert('true');
    }else{
    alert('false');
    }



    You can copy and paste the functions as well as the last code in the form onload event.

     

    Best Regards,

    Imran

     

    http://microsoftcrm3.blogspot.com

     

    Tuesday, February 5, 2008 3:39 AM
    Moderator
    • Proposed as answer by OSUBrenden Monday, July 12, 2010 2:53 PM
    Monday, July 12, 2010 2:53 PM