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.
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() ;
if(phone!=null)
{
alert("Can't deactivate account having phone number.");
}
else
{
Mscrm.CommandBarActions.changeState(parm1,parm2,parm3);
}
}
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.