Peristiwa
Kejohanan Dunia Power BI DataViz
14 Feb, 4 PTG - 31 Mac, 4 PTG
Dengan 4 peluang untuk menyertai, anda boleh memenangi pakej persidangan dan berjaya ke Grand Finale LIVE di Las Vegas
Ketahui lebih lanjutPelayar ini tidak lagi disokong.
Naik taraf kepada Microsoft Edge untuk memanfaatkan ciri, kemas kini keselamatan dan sokongan teknikal yang terkini.
The execution context defines the event context in which your code executes. The execution context is passed when an event occurs on a form or grid. Use it in your event handler to perform various tasks such as determine formContext or gridContext, or manage the save event.
The execution context is passed in one of the following ways:
Defining event handlers using UI: The execution context is an optional parameter that can be passed to a JavaScript library function through an event handler. Use the Pass execution context as first parameter option in the Handler Properties dialog while specify the name of the function to pass the event execution context. The execution context is the first parameter passed to a function.
The execution context object provides many methods to further work with the context. More information: Execution context (Client API reference)
The context passed to an event is only guaranteed to perform as expected during the event. When you keep a reference to a context after the event ends, actions might occur that cause context methods to behave in an unexpected fashion.
For example, if your event handler dispatches an async action that takes an extended amount of time while you're holding on to a reference to the execution context, the end user might navigate away from the current page by the time the promise resolves and you invoke the context method. This situation might cause methods like formContext.getAttribute(<name>).getValue()
to return null
, even though at the time the original event handler executed, the attribute had a value.
The following examples show where you should add more checks and take caution because the event handler function uses the execution context after the event completes.
The context might change in unexpected ways after a promise resolves.
function onLoad(executionContext) {
var formContext = executionContext.getFormContext();
fetch("https://www.contoso.com/").then(
function (result) {
// Using formContext or executionContext here may not work as expected
// because onLoad has already completed when the promise is resolved.
formContext.getAttribute("name").setValue(result);
}
);
}
The context might change in unexpected ways after using await within an async function.
async function onLoad(executionContext) {
var formContext = executionContext.getFormContext();
var result = await fetch("https://www.contoso.com/");
// Using formContext or executionContext here might not work as expected
// because the synchronous part of onLoad has already completed.
formContext.getAttribute("name").setValue(result);
}
The context might change in unexpected ways after using setTimeout or setInterval to defer executing some code.
function onLoad(executionContext) {
var formContext = executionContext.getFormContext();
if (notReady) {
setTimeout(function () {
// Using formContext or executionContext here may not work as expected
// because onLoad has already completed when this delayed function executes.
var name = formContext.getAttribute("name").getValue();
}, 100);
} else {
formContext.getAttribute("name").setValue("abc");
}
}
Client API form context
Client API grid context
Form and grid context in ribbon actions
Peristiwa
Kejohanan Dunia Power BI DataViz
14 Feb, 4 PTG - 31 Mac, 4 PTG
Dengan 4 peluang untuk menyertai, anda boleh memenangi pakej persidangan dan berjaya ke Grand Finale LIVE di Las Vegas
Ketahui lebih lanjutLatihan
Modul
Perform common actions with client script in Power Platform - Training
The goal of this module is to review how to achieve common user experience automation procedures through Client Script. This module is intended to serve as a practical guide for how to solve real-world scenarios that are frequently encountered during Microsoft Power Platform implementations.