Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Force Refresh after Form Save

(0) ShareShare
ReportReport
Posted on by 110

Hello,

I am trying to force refreshing a form after saving it to display the results of the workflow on the form. But I always get a javascript error. I tried to run the following line on the form properties with no success:


Xrm.Page.data.refresh(save).then(successCallback, errorCallback);



I have MS Dynamics CRM 2016 (On-Premise). How can I resolve this?. Thanks

*This post is locked for comments

  • Lucas H Profile Picture
    Lucas H 279 on at
    RE: Force Refresh after Form Save

    Hmm let's try adding the function onLoad, being sure to pass the execution context as the first parameter. If you get the error again, try changing (true) to (false) on the formContext.data.refresh method.

    function onLoad(executionContext) {
       var formContext = executionContext.getFormContext();
        formContext.data.entity.addOnPostSave(refreshForm(executionContext));
    }
    
    function refreshForm(executionContext)
    {
      var formContext = executionContext.getFormContext();
      formContext.data.refresh(true);
    }

  • Pmd18 Profile Picture
    Pmd18 25 on at
    RE: Force Refresh after Form Save

    Hey, its giving the same error.

  • Lucas H Profile Picture
    Lucas H 279 on at
    RE: Force Refresh after Form Save

    You'll need both functions. The refreshForm function is called by the onSave function when the onSave event occurs. Let me know how it goes!

  • Pmd18 Profile Picture
    Pmd18 25 on at
    RE: Force Refresh after Form Save

    Ok and I am adding it on onsave eventhandler and now if there is 2 function should i add both or just onsave the 1st one

  • Lucas H Profile Picture
    Lucas H 279 on at
    RE: Force Refresh after Form Save

    Ah, I'm sorry, my answer was partly wrong. The reason you're getting that error is that it's trying to save twice at the same time - once when you click Save and once during the function called onSave.

    One option is to change it to formContext.data.refresh(false). This won't save form for the refresh. However, I believe this may refresh BEFORE the save action is completed, meaning you may lose data.

    Another option is to use the addOnPostSave method. This adds a function to be called AFTER the save event is completed. For example:

    function onSave(executionContext) {
       var formContext = executionContext.getFormContext();
        formContext.data.entity.addOnPostSave(refreshForm);
    }
    
    function refreshForm(executionContext)
    {
      var formContext = executionContext.getFormContext();
      formContext.data.refresh(true);
    }

    On save, this will add the refreshFrom function the the Post Save event, which will then fire and refresh the form after the save is complete. You can change the (true) to (false) in the refresh method if you don't want the form to save again, but in my experience I often get a pop up asking to save if it's set to (false), so I just leave it at (true).

  • Pmd18 Profile Picture
    Pmd18 25 on at
    RE: Force Refresh after Form Save

    Thanks, its working but only one problem on 1st click of save it shows error called saving in progress please wait while saving is completed

    Error code :- 0x83215603

  • Lucas H Profile Picture
    Lucas H 279 on at
    RE: Force Refresh after Form Save

    Oh I gotcha. Create a Javascript web resource with a function that's called on your desired event. For example:

    function onSave(executionContext) {

    var formContext = executionContext.getFormContext();

    formContext.data.refresh(true)

    }

  • Pmd18 Profile Picture
    Pmd18 25 on at
    RE: Force Refresh after Form Save

    I am trying that only but Can you tell me which web resource will have function of save button. I mean where to add this code?

  • Lucas H Profile Picture
    Lucas H 279 on at
    RE: Force Refresh after Form Save

    Have you tried formContext.data.refresh(true) ? This will save your form and then refresh it as if you'd clicked the Refresh ribbon button.

  • Pmd18 Profile Picture
    Pmd18 25 on at
    RE: Force Refresh after Form Save

    Hi, Did you find solution for this if yes plz let me know as I also have same query.

    Thanks in advance

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

Featured topics

Product updates

Dynamics 365 release plans