locked
Disabling control based on certain condition RRS feed

  • Question

  • Hello everyone,

    I have requirement to disable certain control on the CRM form based on the user's role.
    I am new to CRM & I am not fully sure how can I check user's role through javascript.
    Requirement is that if user has certain roles I need to disable some controls on the form.

    It would be nice if you can put code snippet to show how does it work. Thank you.
    • Edited by Noob_24 Monday, May 5, 2014 4:12 AM
    Monday, May 5, 2014 4:11 AM

All replies

  • Hi,

    Check the below URL which contains the exact code that you want. 

     http://rajeevpentyala.wordpress.com/2011/08/05/check-user-role-in-crm-2011-using-jscript/

    Regards,

    Priya.

    • Proposed as answer by PriyaSwain Monday, May 5, 2014 6:51 AM
    Monday, May 5, 2014 6:50 AM
  • Open the security role and get Guid of the each security role

    you can get guid as shown in figure then make variable with the name of security role and assign id to variable.

    Note:while assign id the alphabetic character should be in small case.

    here is code how add securityroles Guids(ids)

    function test()
    {
    var salesPerson="54810818-fda5-e311-ad13-835e905085a1";
    var salesManager="9f830818-fda5-e311-ad13-835e905085a1";
    var userRoles = Xrm.Page.context.getUserRoles();
    
    //SalesPerson Role
    if(userRoles==salesPerson)
    {
    Xrm.Page.getControl("new_test").setDisabled(false);
    }
    else
    {
    Xrm.Page.getControl("new_test").setDisabled(true);
    }
    //SalesManager Role
    if(userRoles==salesManager)
    {
    Xrm.Page.getControl("new_test2").setDisabled(false);
    }
    else
    {
    Xrm.Page.getControl("new_test2").setDisabled(true);
    }
    }


    Muhammad Sohail


    • Edited by sohail450 Monday, May 5, 2014 9:05 AM
    Monday, May 5, 2014 9:01 AM