This task requires the System Administrator or System Customizer security role A defined set of privileges. The security role assigned to a user determines which tasks the user can perform and which parts of the user interface the user can view. All users must be assigned at least one security role in order to access the system. or equivalent permissions. Customization tasks can be performed only while you are online. More information: Customization Permissions
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.
In the Customization area, click Customize the System.
Under Components, expand Entities, and then expand the entity you want.
Click Forms. In the list, click a form to edit it if it has a Form Type of Main.
On the Home tab, click Form Properties.
On the Events tab, in the Event Handlers section, select onSave or OnLoad, and then click Edit.
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.
On the Non-Event Dependencies tab, in the Available fields list, select any fields you have referenced in scripts, and then click the Add Selected Records button to move the selected fields to the Dependent fields list.
Click OK to close the Handler Properties dialog box.
Click OK to close the Form Properties dialog box.
Click Save and Close to close the form.
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.