Skip to content

Commit 4bbe4f0

Browse files
authored
Merge pull request #3906 from MicrosoftDocs/stjanovi-patch-3
Update form onload description
2 parents fdce911 + 82491e1 commit 4bbe4f0

File tree

1 file changed

+8
-5
lines changed
  • powerapps-docs/developer/model-driven-apps/clientapi/reference/events

1 file changed

+8
-5
lines changed

powerapps-docs/developer/model-driven-apps/clientapi/reference/events/form-onload.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "Form OnLoad Event (Client API reference) in model-driven apps| MicrosoftDocs"
3-
ms.date: 10/31/2018
3+
ms.date: 12/14/2020
44
ms.service: powerapps
55
ms.topic: "reference"
66
applies_to: "Dynamics 365 (online)"
@@ -17,14 +17,17 @@ search.app:
1717
# Form OnLoad Event (Client API reference)
1818

1919

20+
The form `OnLoad` event occurs after the form has loaded. It also occurs after a record is created, for example by selecting the **Save** button on the main form. Use the `OnLoad` event to apply logic about how the form should be displayed, to set properties on fields, and interact with other page elements.
2021

21-
The form `OnLoad` event occurs after the form has loaded. It also occurs after a record is created, for example by selecting the **Save** button on the main form. It cannot prevent the window from loading. Use the `OnLoad` event to apply logic about how the form should be displayed, to set properties on fields, and interact with other page elements.
22+
You can determine in what context the `OnLoad` event occurs by using [getEventArgs](../executioncontext/getEventArgs.md). By doing so, you can apply logic conditional on the context.
2223

23-
You can determine in what context the `OnLoad` event occurs by using [getEventArgs](../executioncontext/getEventArgs.md). By doing so, you can apply logic conditional on the context.
24+
Data for related entities on a form, such as data for subgrids and quick view forms are not guaranteed to be available when the `OnLoad` event handler is executed. Logic that depends on related data should use the [Subgrid OnLoad](https://docs.microsoft.com/powerapps/developer/model-driven-apps/clientapi/reference/events/subgrid-onload) event, quick view form should use the [isLoaded](https://docs.microsoft.com/powerapps/developer/model-driven-apps/clientapi/reference/formcontext-ui-quickforms/isloaded) function, or the appropriate function for determining when the data should be loaded for the particular related data.
2425

25-
The form `OnLoad` events are synchronous. However, you should **not** make synchronous network requests in an `OnLoad` event handler. This can cause a slow save experience and an unresponsive app. Instead, you can make asynchronous network requests.
26+
Controls and other UI of the form are not guaranteed to be rendered and in the DOM when the `OnLoad` event occurs. Logic in the `OnLoad` event handler cannot prevent the form from loading.
2627

27-
You should be careful when using asynchronous code in an OnLoad event handler that needs an action to be taken or handled on the resolution of the async code. Asynchronous code can cause issues if the resolution handler expects the app context to remain the same as it was when the asynchronous code has started. For example, there may be code in an `OnLoad` event handler to make a network request and change a control to be disabled based on the response data. Before the response from the request is receieved, the user may have interacted with the control or navigated to a different page, so there may be undesired behavior.
28+
The form `OnLoad` events are synchronous. However, you should **not** make synchronous network requests in an `OnLoad` event handler. This can cause a slow save experience and an unresponsive app. Instead, you should [asynchronous network requests](https://docs.microsoft.com/powerapps/developer/model-driven-apps/best-practices/business-logic/interact-http-https-resources-asynchronously). Using asynchronous requests will [dramatically improve the performance of form loads](https://powerapps.microsoft.com/blog/turbocharge-your-model-driven-apps-by-transitioning-away-from-synchronous-requests/) compared to using synchronous requests.
29+
30+
You should be careful when using asynchronous code in an `OnLoad` event handler that needs an action to be taken or handled on the resolution of the async code. Asynchronous code can cause issues if the resolution handler expects the app context to remain the same as it was when the asynchronous code has started. For example, there may be code in an `OnLoad` event handler to make a network request and change a control to be disabled based on the response data. Before the response from the request is received, the user may have interacted with the control or navigated to a different page, so there may be undesired behavior. If you need to not show data or UI before the asynchronous requests complete, your code can hide or disable the relevant UI until the requests are complete. Your code should also check that the user is in the same context after each asynchronous continuation point.
2831

2932

3033

0 commit comments

Comments
 (0)