From 8883b899108653d7d047bbc898793f387b2f472e Mon Sep 17 00:00:00 2001 From: Adam Naji <110662505+Bashamega@users.noreply.github.com> Date: Wed, 12 Aug 2026 21:06:33 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#75380=20Add=20new?= =?UTF-8?q?=20methods=20to=20Xrm.Ui=20interface=20for=20handling=20form=20?= =?UTF-8?q?Loaded=20events=20by=20@Bashamega?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/xrm/index.d.ts | 13 +++++++++++++ types/xrm/xrm-tests.ts | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/types/xrm/index.d.ts b/types/xrm/index.d.ts index 0e6a58a3f4136d..6dd01bbadbe084 100644 --- a/types/xrm/index.d.ts +++ b/types/xrm/index.d.ts @@ -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. @@ -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. diff --git a/types/xrm/xrm-tests.ts b/types/xrm/xrm-tests.ts index 8fc1d20092c6bf..5aa6c99491c672 100644 --- a/types/xrm/xrm-tests.ts +++ b/types/xrm/xrm-tests.ts @@ -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"],