Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions types/xrm/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,13 @@ declare namespace Xrm {
* @see {@link https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/formcontext-ui External Link: formContext.ui (Client API reference)}
*/
interface Ui {
/**
* Adds a function to be called on the form Loaded event.
* The function will be added to the bottom of the event handler pipeline.
* @see {@link https://learn.microsoft.com/power-apps/developer/model-driven-apps/clientapi/reference/formcontext-ui/addloaded External Link: ui.addLoaded (Client API reference)}
*/
addLoaded(handler: Events.LoadEventHandler | Events.LoadEventHandlerAsync): void;

/**
* Adds a function to be called on the form OnLoad event.
* The function will be added to the bottom of the event handler pipeline.
Expand Down Expand Up @@ -1303,6 +1310,12 @@ declare namespace Xrm {
*/
removeOnLoad(handler: Events.LoadEventHandler | Events.LoadEventHandlerAsync): void;

/**
* Removes a function from the form Loaded event.
* @see {@link https://learn.microsoft.com/power-apps/developer/model-driven-apps/clientapi/reference/formcontext-ui/removeloaded External Link: ui.removeLoaded (Client API reference)}
*/
removeLoaded(handler: Events.LoadEventHandler | Events.LoadEventHandlerAsync): void;

/**
* Sets the name of the table to be displayed on the form.
* @param name Name of the table to be displayed on the form.
Expand Down
19 changes: 19 additions & 0 deletions types/xrm/xrm-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,25 @@ function testOnLoadTypes(formContext: Xrm.FormContext) {
}
}

function testLoadedTypes(formContext: Xrm.FormContext) {
formContext.ui.addLoaded(onLoaded);
formContext.ui.removeLoaded(onLoaded);

function onLoaded(eventContext: Xrm.Events.LoadEventContext) {
eventContext.getEventArgs().getDataLoadState() === 2;
}

formContext.ui.addLoaded(asyncOnLoaded);
formContext.ui.removeLoaded(asyncOnLoaded);

async function asyncOnLoaded(eventContext: Xrm.Events.LoadEventContextAsync) {
const eventArgs = eventContext.getEventArgs();
eventArgs.disableAsyncTimeout();

eventArgs.getDataLoadState() === XrmEnum.FormDataLoadState.Refresh;
}
}

// Demonstrate Xrm.Utility.lookupObjects parameters
Xrm.Utility.lookupObjects({
entityTypes: ["contact"],
Expand Down