Form and Field Events
[Applies to: Microsoft Dynamics CRM 4.0]
You can add scripts for the onLoad and OnSave events for the form and OnChange events for each field.
Note Form and field events are disabled for the bulk edit form. The bulk edit form is displayed when multiple records in a list are edited.
The onLoad event occurs after the form has loaded. It cannot prevent the window from loading. Use the onLoad event to prepare the data in the form for use. Some actions that can be performed using the onLoad event include:
- Perform calculations based on changing values
- Alert a user of a situation
- Disable fields which should not be updated
- Set a target for an IFRAME based on data in the form.
The OnSave event does not correspond to the standard HTML OnSubmit event. It occurs when a user presses the Save or Save and Close buttons or other actions which cause the form to be saved, such as using the Save method. The event always occurs, even when the data in the form hasn't changed.
It is possible to detect which user action was performed to save the form using the Event.Mode property in the OnSave event.
The OnSave event can be cancelled to prevent the data from being saved. Because of this it is very common to use the OnSave event to validate data.
The onChange event is available on every field. The OnChange event requires two conditions to be true:
- The data in the field must change.
- The field must lose focus.
After the event the data in the field will be re-validated. This means it is not possible to use the event to enter invalid data.
Some actions that can be performed using the onChange event include:
- Perform calculations to change other fields based on changing values.
- Change the formatting of fields such as phone numbers.
- Implement dynamic picklists (drop-down lists).
Note If you add code to the OnChange event for a field, the field will be disabled in the bulk edit form. The bulk edit form is displayed when multiple records in a list are edited.
© 2010 Microsoft Corporation. All rights reserved.