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
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); }
Hey, its giving the same error.
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!
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
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).
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
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)
}
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?
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.
Hi, Did you find solution for this if yes plz let me know as I also have same query.
Thanks in advance
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,228 Super User 2024 Season 2
Martin Dráb 230,056 Most Valuable Professional
nmaenpaa 101,156