Tuesday, 24 May 2016

How to implement enable rule on a ribbon button using ribbon Workbench in MS CRM

Hello Folks,
In this post we are going to learn how to implement enable rule on a system/custom button on ribbon of MS CRM form using ribbon workbench solution.


Here i have created a step by step procedure of implementing enable rule in MS CRM.
The test scenario i have created is as follwos:

1. Entity  : Task
2. Button : Convert to Case
3. Event  : On the value of option set field Priority


The test scenario is such that Covert to case button should be only visible on Task entity when Priority field is set to High otherwise Convert to Case button should be hidden.



I have included following javascript function in a library to check the value of Priority field:


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function enbleconverttocase()
{
var value =Xrm.Page.getAttribute("prioritycode").getValue();
if(value!=null)
{
if(value ==2) //Value 2 = Priority High
return true;
else
return false;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Step 1 :
a) Open the desired solution which contain your entity on which you want to implement enable rule and the library having javascript function similar to the one above.

Note: For fast load and upload/publish of solution, keep solution small i.e. don't add unnecessary components.

In my case solution name is test enable  rule:

b) Select the desired solution and click OK

Step 2: Right click on the desired button and click Customise command.

In my case it's "To Case".

Step 3: 
a) You'll see command as shown in image below.

b) No need to do anything here.

Step 4: Right Click on enable rule and select add new.


Step 5: 
a) A new enable rule will be created below Enable rule.
b) Right click on the new rule created and click add new.


Step 6: Select Custom javascript rule and click add.

Step 7: Now right click on the created enable rule and select Edit enable rule.


Step 8:  

a)Now edit your custom rule as shown below:

  • Default                 :      True
  • Function Name :      enbleconverttocase (write yours)
  • Invert Results    :      False
  • Library                 :      Select library containing your function
  • Parameters         :      NA(leave blank) 
b) Click OK




Step 9: 

a) Now you need to right click on the desired command and select edit enable rule and  select the created rule and move it to the box in the right side.



b) Here we have moved it to the box in the right side.


c) Click OK

Step 10: Now publish your solution. It's done.


Note: In case you  want this show hide of button according to different conditions, you just need to manipulate the js function according to your requirements. Rest steps will be same.

In case of any query, leave a comment.












No comments:

Post a Comment