!

Use JavaScript(JScritp) to customize Microsoft Dynamics CRM



Use JavaScript(JScript) to customize Microsoft Dynamics CRM 


Microsoft Dynamics CRM platform allows customization at different levels in the platform. A good amount if customization can be done using CRM web application though GUI itself. Using JavaScript, we can write event handlers for form events for custom business logic implementation. This kind of customization  is known as form scripting or form-level customization.



Some of the scenario where we can use JavaScript for business logic implementation are:
  • To trigger a calculation on a form when a field is updated 
  • The user shouldnt be able to edit a calculated field



Areas Where You Can Use JavaScript in Microsoft Dynamics CRM

You can use JavaScript to perform actions in form scripts, ribbon commands, and web resources.

Form Scripts

JavaScript in Microsoft Dynamics CRM is mostly used to add functions as event handlers for entity form events. 

Ribbon Commands

When we do ribbon customization in Microsoft Dynamics CRM ribbon, you can use JavaScript to set commands for controls(buttons) that you add. These commands are nothing but JavaScript functions that control whether the control is enabled and what action is performed when the control is used. 

Web Resources

JavaScript files can be added as web resources which can later use for form customization. You can use a webpage (HTML) web resource to provide a user interface with JavaScript libraries included just as you would for files on a web server.

JavaScript Example:

When the user select the Address Type of account as 'Primary', the form field 'city' should be business required( mandatory) so that user should fill it up to submit.
//City Required if Address Type if Primary
debugger;function city_required(){
if(Xrm.Page.getAttribute("address1_addresstypecode").getValue()!=null){
  if(Xrm.Page.getAttribute("address1_addresstypecode").getSelectedOption().text=="Primary")   {     Xrm.Page.getAttribute("address1_city").setRequiredLevel("required");   }  else{    Xrm.Page.getAttribute("address1_city").setRequiredLevel("none");    }  }

}