How to override out of the box button’s behavior in ms crm

In crm, sometime we want to override the operation being performed by oob or we want to perform action only if certain conditions are met.

In this post,i’ll share how we can override the out of the box button’s behavior.

Scenario: We have deactivate button on account record. We want that only if field named phone doesn’t contains data, then only deactivation should be allowed otherwise system should show and alert and don’t deactivate the record.

Below is step by step solution for above problem:

Step 1:

Add the account entity having that button in a solution along with a javascript library


Step 2:

Open that solution using ribbon workbench as shown below:


Step 3:

Right click on the deactivate button and click on customize command as shown below:


Step 4:

Now click on deactivate command and change the library to your javascript library i.e. “new_account”. Also copy the function being called on that command (ref 3 in below screen shot). This function will be used in out javascript function. It’s “Mscrm.CommandBarActions.changeState” in our case.


Step 5:

Replace the oob function with your function name (“overridedeactivatebtn” in our case)


Keep in mind here 3 parameters are being passed. We’ll pass these three parameters when we’ll call oob function “Mscrm.CommandBarActions.changeState” from our js fucntion.

Step 6:

Publish the solution in ribbon workbench:


Step 6:

In new_account library, overridedeactivatebtn function will have below code.

function overridedeactivatebtn(parm1,parm2,parm3)
  var phone= Xrm.Page.getAttribute("telephone1").getValue() ;
  alert("Can't deactivate account having phone number.");

Publish your javascript library.

Step 7:

To test click on deactivate button on account record having value in phone number field and you’ll get the alert message and no oob pop up of deactivation will come:


Now, clear the phone field and click deactivate again. CRM’s oob deactivation pop-up will come:


So, we successfully override the  functionality of   out of the box crm button.

Hope it would be helpful..!


One thought on “How to override out of the box button’s behavior in ms crm

Add yours

  1. This functionality is not working I did exactly the same and it is not working as else part giving the changeState is undefined


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

Up ↑

%d bloggers like this: