DEV Community

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

Posted on

1

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

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay