Skip to main content
Dynamics 365 general forum
Answered

Refresh section on field change

editSubscribe (0) ShareShare
ReportReport
Posted on by 98

Hi everyone,

 

I have a Power Automate Flow which updates a field on a custom dataverse table.

 

Could anyone share the JS syntax for automatically refreshing the section or page when that field changes? The reason I think I would need to refresh the section/page (the equivalent of clicking the Refresh button) is that I have an embedded canvas app in a section which needs to be updated when the field value changes.

 

My thinking is that I could place the field in a different section and run the JS function on the OnChange property against it.

best regards,

8015.picture1.png

  • Suggested answer
    maeneak Profile Picture
    maeneak 7 on at
    Refresh section on field change
    I came up with a messy workaround using the OnChange event of the control. It triggers a save when the field is 'Dirty' which in turn triggers the flow, then run through a few nested setTimeout's and use showProgressIndicator to restrict/notify the user. I just picked a timeout value I was sure would cover the flow run time, but this is obviously not guaranteed for long flows.
     
    function SaveFormOnChangeIfDirty(primaryControl, fieldName, interval) {
        var formContext = primaryControl.getFormContext();
        var field = formContext.getAttribute(fieldName);
        if (field.getIsDirty() && field.getValue() != null) {
            formContext.data.save();
            Xrm.Utility.showProgressIndicator("Running flows and updating data...");
            setTimeout(function() {
                formContext.data.refresh();
                Xrm.Utility.closeProgressIndicator();
            }, interval);
        }
    }
     
  • ImranAmi Profile Picture
    ImranAmi 98 on at
    RE: Refresh section on field change

     Eiken  Thank you for the solution. Unfortunately, although the function triggers perfectly when changing a field inside the form, it seems a javascript function cannot trigger when a field has been changed by an external connector (in this case, Power Automate).

    There is a Power Automate flow which updates that field. In the video below, you can see the event triggers when I change the field directly inside the form, but the event does not trigger when a Power Automate Flow changes that field.

    I still find your solution very helpful though so I marked as Solved.

    If you happen to know if it is indeed possible to trigger the refresh, please let me know.

    [View:/cfs-file/__key/communityserver-discussions-components-files/761/recording.mp4:1440:1080]

  • Verified answer
    Eiken Profile Picture
    Eiken on at
    RE: Refresh section on field change

    Hi,

    Please use the following API:

    formContext.data.refresh(save).then(successCallback, errorCallback); 

    Please check the detail of this API.

    data.refresh (Client API reference) in model-driven apps - Power Apps | Microsoft Learn

    Now please refer to my steps.

    Edit the refreshpage function.

    function refreshpage(e){
        var formContext = e.getFormContext();
        formContext.data.refresh(true).then(function(result){
            alert('Refreshed!!')
        });
        }

    Add On change event to the selected field.(Now I choose ""Name")

    pastedimage1681263834961v1.png

    It works well.

    pastedimage1681263921683v2.png

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,066 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,585 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans