Enable/Disable Custom Enity's Save Button Based on Security Role??

Proposed Answer Enable/Disable Custom Enity's Save Button Based on Security Role??

  • Monday, June 18, 2012 5:47 AM
     
     

    Hai All,

    I have a custom entity and i need to enable or disable the save button of the custom entity based on security role.For system entity we can get the command definition Id for custom entity how can we do this??

All Replies

  • Monday, June 18, 2012 6:43 AM
     
     

    I suggest you to control that by security role. (removing Write access as shown below)

    But if you insist on disabling the save button, you can try using the command definition IDs as the same with the system buttons since those are quite standard.

  • Monday, June 18, 2012 7:05 AM
     
     Proposed Answer Has Code

    Hai All,

    I have a custom entity and i need to enable or disable the save button of the custom entity based on security role.For system entity we can get the command definition Id for custom entity how can we do this??

    Hello Srikanth A:

    If you are creating some custom buttons and want to achieve this functionality or even for CRM inbuilt buttons, use this approach

    var currentUserId = Xrm.Page.context.getUserId(); var roles; var odataSelect = GetODataPath() + "/SystemUserSet(guid'" + currentUserId + "')/systemuserroles_association?$select=Name"; $.ajax({ type: "GET", contentType: "application/json; charset=utf-8", datatype: "json", url: odataSelect, async: false, beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); }, success: function (data, textStatus, XmlHttpRequest) { if (data) { roles = GetSecurityRolesSuccessCallback(data.d); } }, error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + odataSelect); } }); return roles; } function GetSecurityRolesSuccessCallback(data) { var roles = new Array(); if (data.results.length > 0) { for (var i = 0; i < data.results.length; i++) { roles[i] = data.results[i].Name; } } return roles; }

    //Now you have the all the roles of the current logged in user in an Array.

    //Make a for loop to iterate through this array and simply put the logic to hide/ show the buttons for desired roles.

    If this approach solves your problem, kindly do a favor by marking this as correct solution...Thanks in advance.


    Saurabh Gupta, MS CRM 2011 Software Development Engineer


  • Monday, June 18, 2012 7:35 AM
    Answerer
     
     Proposed Answer

    In addition to the above comments, you can read in security roles without Javascript using Ribbon Customisation Rules:

    The following post shows disabling the activate-deactive buttons, but can equally apply to the save buttons.

     http://blog.customereffective.com/blog/2012/05/managing-activatedeactivate-permissions-of-crm-entities.html

    hth,

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Proposed As Answer by Linn Zaw Win Monday, June 18, 2012 7:38 AM
    •