Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Refresh section on field change

(0) ShareShare
ReportReport
Posted on by 100

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);
        }
    }
     
  • Ami K Profile Picture
    Ami K 100 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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans