Saturday, September 1, 2012

Crm 2011 - Hidding Ribbon button based on partylist value by using javascript

 function SetRibbonButtonVisiblity()
{

var approvers = Xrm.Page.getAttribute("to").getValue();
var isApprover=false;
if(approvers != null)
{
    for (var index= 0; index < approvers.length; index++)
    {
      if (approvers[index].type == 8)
       {
        var UserGUID = Xrm.Page.context.getUserId();
        if(approvers[index].id == UserGUID)
        {
        isApprover=true;
        }
       }
     }
}

if(isApprover == false)
{
var approveButton= window.top.document.getElementById("jmh_approvalrequest|NoRelationship|Form|Ntier.Form.jmh_approvalrequest.MainTab.Actions.Accept-Large");

var rejectButton= window.top.document.getElementById("jmh_approvalrequest|NoRelationship|Form|Ntier.Form.jmh_approvalrequest.MainTab.Actions.Reject-Large");


if(approveButton != null && rejectButton != null)
{
approveButton.style.display='none';
rejectButton.style.display='none';
}
}

    }

Note : you can get ribbon button id by pressing F12.
To get or set partylist
http://rajeevpentyala.wordpress.com/2012/04/02/get-and-set-partylist-fields-using-jscript/
Reference:
http://www.ahmetcankaya.com/hide-ribbon-button-in-crm-2011-by-using-javascript/

No comments:

Post a Comment