JavaScript and HTML Resources

In this chapter we will take a look at integrating JavaScript and HTML Web Resources within Dynamics CRM. We will discuss when and why you would choose JavaScript in CRM as well as provide some examples.

This chapter will incorporate the uses of Javascript within the context of a script, ribbon commands, and web resources. We will spotlight how Javascript is added to Dynamics CRM and how we can associate functions with events on the form, specifically during the following events, Onload, OnSave, and OnChange. Subsequently we will spotlight the Javascript CRM model. As we delve further into this chapter we will stress the importance of following industry best practices. The best practices section will focus on obvious items such as avoid using unsupported code and use safe and efficient logic. Additionally we will show the value of keeping your coding simple to prevent confusing elements.

Jump to the following sections to learn more:

Why and when to use JavaScript in CRM

The following outlines scenarios where you should use JavaScript in Microsoft Dynamics CRM.

Form Scripts

When using JavaScript, you want to have actions performed in form scripts. This is essentially form programming. Because the results of this style are instantaneous, it is the most preferred method and the most used. It is also highly adaptable to interact with various customer scenarios. Form scripts are used most for the following tasks:

  • Data Validation
  • Automation
  • Process enhancement and enforcement

You’ll want to configure commands for the controls you add to the ribbon command. There are three items that the ribbon command delineates:

  • Enabling rules
  • Displaying rules
  • Actions
Tip! Take a look at the MSDN resource: Write Code for Microsoft Dynamics CRM Forms for more information.

Ribbon Command

You have the ability to delineate at what point ribbon elements are enabled. The <EnableRule> (RibbonDiffXml) element is used as follows:

  • Use the /RuleDefinitions/EnableRules/EnableRule element to define rules controlling when the ribbon element should be enabled.
  • Use the /CommandDefinitions/CommandDefinition/EnableRules/EnableRule element to associate specific enable rules to a command definition.
Tip! A list of enabling rules can be located in the MSDN developer network: Define Ribbon Enable Rules

You also have the ability to delineate at what point ribbon elements are displayed.

  • Use the /RuleDefinitions/DisplayRules/<DisplayRule> (RibbonDiffXml) element to define rules controlling when the ribbon element should be displayed.
  • Use the /CommandDefinitions/CommandDefinition/DisplayRules/<DisplayRule> (RibbonDiffXml) element to associate specific display rules to a command definition.
Tip! A list of enabling rules can be located in the MSDN developer network: Define Ribbon Display Rules

Finally, you also have the ability to delineate the actions performed by a ribbon control in a <CommandDefinition> (RibbonDiffXml) element together with rules that control whether the control is enabled or visible in the ribbon.

A ribbon control can perform two types of actions and may include multiple actions:

  • JavaScript Functions: A <JavaScriptFunction> (RibbonDiffXml) element references a function defined in a Script Web resource.
  • Open a URL: The ribbon opens a URL using the value from an Address attribute in the <Url> (RibbonDiffXml) element. Additional parameters can pass information about how what query string parameters are passed and the mode in which the window opens.
Tip! You have several options to pass parameters to a URL using the ribbon. For more information, see Pass Parameters to a URL By Using the Ribbon

Additional resources



Return to Top ▲Return to Top ▲