Wednesday, July 27, 2011

disable a button in ribon on basis of a attribute value in the form in MS CRM 2011

sometimes we have to hide some buttons in ms crm 2011.
that we can do and i hv posted in some of my post, bu using the HideCustomAction tag.

Here i will put how to disable a button on basis of a logic or value (also can be done by user role) on the form of ms crm 2011.

1st you need to export the entity.

Then find the id of the button, then get command value from the button tag.
now go to the comanddefinitions tag and find the comamnddefition with the corresponding id.
Inside that u will have to declare your enablerules tag as follows
<EnableRule Id="" />
then go RuleDefinitions tag insdie the same xml file and define the rule for enable as below
<EnableRule Id="">
<CustomRule FunctionName="disableEditButton" Library="$webresource:<js file name.js" /> //here u can define the js file u have kept the webresources and also the functionname which will be executed for this

In your js file you can have the fucntion as declared.
main thing is write your logic and return boolean value.
suppose i am just checking is an attribute has value then only i will make enabled else disabled.
function disableEditButton(){
if("<attributename>").getValue() != null){
return false; // false means it will be disabled
return true; //means it will be true

hope this will help.
even you can use the valuerule tag to push direct values in the xml file.

No comments:

Post a Comment