Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Use Form and Field Events

[Applies to: Microsoft Dynamics CRM 2011]

You can add scripts for the OnLoad and OnSave events for the form and OnChange events for each field. Tabs have a TabStateChange event and IFRAMES have an OnReadyStateComplete event.

noteNote
Events in the form are disabled for the bulk edit form. The bulk edit form is displayed when multiple records in a list are edited.

In This Topic

OnLoad Event

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 by using the OnLoad event include the following:

  • Perform calculations based on changing values.

  • Alert a user to a situation.

  • Disable fields that should not be updated.

For more information, see OnLoad Event.

OnSave Event

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 that cause the form to be saved, such as the Save method. The event always occurs, even when the data in the form hasn't changed.

You can detect which user action was performed to save the form by using the getSaveMode method in the save event arguments retrieved from the getEventArgs method execution context.

The OnSave event can be canceled to prevent the data from being saved. Because of this it, is very common to use the OnSave event to validate data.

For more information, see OnSave Event

OnChange Event

The OnChange event is available on every field. Generally, the OnChange event requires two conditions to be true:

  • The data in the field must change.

  • The field must lose focus.

noteNote
There is an exception to this behavior after Microsoft Dynamics CRM 2011 Update Rollup 12 and Microsoft Dynamics CRM December 2012 Service Update. This exception applies to Two-Option (Boolean) fields that are formatted to use radio buttons or check boxes.

  • When Two-Option (Boolean) fields are formatted to use radio buttons, the OnChange event occurs immediately without requiring that the field lose focus.

  • When Two-Option (Boolean) fields are formatted to use check,boxes, the OnChange event occurs immediately without requiring that the field lose focus except when the browser is Internet Explorer 7 or 8. In this case, the control must lose focus before the OnChange event occurs.

The OnChange event does not occur if the field is changed programmatically using the setValue method. If you want event handlers for the OnChange event to run after you set the value, you must use the fireOnChange method in your code.

After the event, the data in the field will be revalidated. This means that you cannot use the event to enter invalid data.

Some actions that can be performed by using the OnChange event include the following:

  • Perform calculations to change other fields based on changing values.

  • Change the formatting of fields, such as telephone numbers.

  • Implement dynamic picklists (drop-down lists).

For more information, see Field OnChange Event.

TabStateChange Event

This event occurs when a tab is expanded or collapsed. You may want to defer execution of code until a tab is expanded.

This event is important if you are using script to modify the src property of an IFRAME control. An IFRAME will be refreshed when the tab is expanded. Any changes to the src property will be removed. If you interact with the src property of an IFRAME, you should always include this code in the TabStateChange event instead of the Onload event.

For more information, see Tab TabStateChange Event.

OnReadyStateComplete Event

Any script that interacts with the contents of an IFRAME will fail unless the contents of the IFRAME has completed loading. This event provides a location to include script that will execute as soon as the contents of the IFRAME have completed loading.

For more information, see IFRAME OnReadyStateComplete Event.

See Also

Microsoft Dynamics CRM 2011
Send comments about this topic to Microsoft.
© 2013 Microsoft Corporation. All rights reserved.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.