DEV Community

Cover image for Force refresh of custom scripts in Power Platform model-driven apps
Kinga
Kinga

Posted on

Force refresh of custom scripts in Power Platform model-driven apps

How do you force custom script refresh in your Model Driven apps?

I’m sure it’s sometimes OK to wait until the problem will solve itself, but if you delete a column that the script is referencing, the user will see an error.
That’s not a great experience.

Me, I’m using the Form.OnLoad event to compare the version defined in the form with a version declared in the JavaScript.

For example, the following file is added as a WebResource to my solution:

var ECSLibrary = window.ECSLibrary || {};
(function () {

    const currentVersion = "0.1.1.3";

    this.OnFormOpen = function (executionContext, versionNumber) {

        const formContext = executionContext.getFormContext();

        if (currentVersion !== versionNumber) {
            formContext.ui.setFormNotification("The form is outdated. Please refresh the page using Ctrl+F5 buttons.", "WARNING");
        }
    }
}).call(ECSLibrary);
Enter fullscreen mode Exit fullscreen mode

And associated with the form’s OnLoad using the current configuration:

Image description

Every time I’m making changes, I increase the version number in both places. If the user has old, cached script version, the numbers will differ and a warning is displayed on top of the page.

And if you are using Dataverse DevTools, and writing code in typescript it's very similar:

const currentVersion = "0.1.1.3";

export const OnLoad = (executionContext: Xrm.Events.EventContext, versionNumber:string): void =>
    const formContext: Xrm.Idapps_externalcloudservice = executionContext.getFormContext();

    if (currentVersion !== versionNumber) {
        formContext.ui.setFormNotification("The form is outdated. Please refresh the page using Ctrl+F5 buttons.", "WARNING","_formVerWarning");

    }
};
Enter fullscreen mode Exit fullscreen mode

Image description

Top comments (0)