Posted in CRM, RibbonWorkBench

Enable/Disable a ribbon button dynamically based on a form value

Enable/Disable a ribbon button dynamically based on a form value

Recently , we had a requirement , that the custom button must be visible  based on the  form value. we can achieve this requirement in two ways

  1. Value Rule  and 2. Custom Code Rule.

Value Rule- 

Based on one and only one value, the button will be visible or disabled. if u hv to hide button based on 2 or more form field values go with ” Custom Rule ” or ” OR Rule between value rule  “.

Go to- Command- Display Rule- Value Rule

Manually enter filed name and value.. If value equal to that filed then only the button will be visibled otherwise button will be on hidden mode.

screenshot-338.png

Custom Rule 

Go to- Enable rules- Custom Rule.

It will ask the function name and web resource name. Before that add the web resource in Ur solution, so that when u click on search button it will display and select that web resource. give Exact function name .

screenshot-337.png

web resource – JavaScript code as follows:-

//button will be visible when name exactly equals to "gb".Otherwise button Goes to hide
function hide(){
 var name = Xrm.Page.getAttribute("name").getValue();
if(name=="gb")
 return true;
 else
 return false;
}

Add the above Enable rule to command and attach the command to button.

Thats it.

Crming- Enjoy 🙂