Configure model-driven app form event handlers
Effective November 2020:
- Common Data Service has been renamed to Microsoft Dataverse. Learn more
- Some terminology in Microsoft Dataverse has been updated. For example, entity is now table and field is now column. Learn more
This article will be updated soon to reflect the latest terminology.
Form event handlers for Power Apps forms can be configured for the following areas in a form:
||Occurs when the form loads.|
||Occurs when data is saved.|
||Occurs when the tab is expanded or collapsed.|
||Occurs when data in the column changes and the control loses focus.|
||Occurs when the content of an IFRAME loads.|
Configuring an event handler incorrectly can result in script errors that may cause the form to fail to load or function correctly. If you are not the developer of the script, make sure you understand exactly what configuration options the script requires.
Do not configure a script event handler using a library that does not come from a source you trust. Scripts can be used to perform any action a user might perform and a poorly written script can significantly damage the performance of a form.
After you configure an event handler always test it to verify it is working correctly.
To configure an event handler
In the form editor, select the element with the event you want to configure a handler for.
On the Home tab, in the Edit group, select Change Properties or simply double-click the element.
In the element properties dialog, select the Events tab.
Expand the Form Libraries area. If the library containing the function you want to set as the event handler is not already listed, add the library.
To add a form library to an event handler:
In the Form Libraries section of the Event List, select Add.
In the web resource form set the following properties:
Property Value Name Required. Type the name of the web resource. Display Name Required. Type the name to be displayed in the list of web resources. Description Optional. Type a description of the web resource. Type Required. Select Script (JScript). Language Optional. Choose one of the languages available for your organization.
If you have been provided with a script, we highly recommend that you use the Browse button to locate the file and upload it.
Alternatively, you can select the Text Editor button and paste or type the contents of the script in the Edit Content dialog.
Because this simple text editor does not provide any features to check the correctness of the script, generally you should always try to use a separate application like Visual Studio to edit scripts and then upload them.
Select Save and close the web resource dialog.
The web resource you created is now selected in the Look Up Row dialog. Select Add to close the dialog.
In the Event Handlers section, select the event you want to set an event handler for.
Select Add to open the Handler Properties dialog.
On the Details tab choose the appropriate library and type the name of the function that should be executed for the event.
By default the event handler is enabled. Clear the Enabled checkbox if you do not want to enable this event.
Some functions require an execution context to be passed to the function. Select Pass execution context as the first parameter if it is required.
Some functions can accept a set of parameters to control the behavior of a function. If these are required, enter them in the Comma separated list of parameters that will be passed to the function.
On the Dependencies tab, add any columns that the script depends on into the Dependent Columns area.
Select OK to close the Handler Properties dialog.
When the event handler is entered you may adjust the order in which the function will be executed relative to any other functions by using the green arrows to move it up or down.
Select OK to close the element properties dialog.
Select Save to save your changes. Select Publish to publish the form.
While the user interface (UI) lets you adjust the order in which the scripts are loaded by using the up and down green arrows, the scripts are actually not loaded sequentially.