Add event handlers for field events

Can I do this task?

Always set dependencies on any form fields referenced in your scripts. Removing a field that a script references causes an error when the script runs. Set such a field as dependant helps to prevent the accidental removal of a field that a script references. More information: Form Scripting

You should have a thorough knowledge of JScript programming syntax and an understanding of the Xrm.Page object model before adding scripts, and should test your scripts before you publish customizations. Malformed scripts can prevent the form from working correctly.

  1. In the Navigation Pane, click Settings.
  2. Under Customization, click Customizations.
  3. In the Customization area, click Customize the System.
  4. Under Components, expand Entities, and then expand the entity you want.
  5. Click Forms. In the list, click a form to edit it if it has a Form Type of Main.
  6. On the Home tab, in the Select group, click Body.
  7. In the main pane, double-click the field to which you would like to add an event.
  8. In the Field Properties dialog box, on the Events tab, select one of the available events, and then click Add.
  9. In the Handler Properties dialog box, supply the requested information. Select the Enabled check box to make the function available to be called by a field event.
  10. Click OK to close the Handler Properties dialog box.
  11. Click OK to close the Field Properties dialog box.
  12. Test your script in the three modes a form can be used: create, update, and read-only:
    1. On the Home tab, click Preview, and then select Create Form, Update Form, or Read-Only Form.
    2. For the create and update modes, enter data in the field and move focus off the field by selecting a different field to verify that the script executes.
    3. To close the Preview form, on the File menu, click Close.
  13. Click Save and Close to close the form.
  14. When your customizations are complete, publish them:
    • To publish customizations for only the component that you are currently editing, on the Home tab, in the Save group, click Publish.
    • To publish customizations for all unpublished components at one time, click Publish All Customizations.

Related Topics

Create and Configure Entity Forms

Form Scripting

Understanding Entities

Test an event script

Did you find the information that you need?
Yes      No 
If not, what information do you need? (optional)