web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Refresh web resource/form AFTER record save

(0) ShareShare
ReportReport
Posted on by 3,499

Hi All!

Historical Context
I have a custom HTML web resource placed on the Quotes form.
The HTML web resource uses the 'Record ID' to determine if the web resource has to be loaded or not.
So, if record Id is null (as in the case of a new record), we display a message saying 'Save this record to enable the content'.
However, after save of the record, the web resource does not refresh on its own (since the record ID is null).

If I manually refresh the page after the record is saved, the HTML web resource gets a valid 'Record ID' and then loads the web resource.

Requirement
On reading through the MSDN blogs, I came across two ways to achieve this:
1. Refresh the Form AFTER Save of the record. 
2. Refresh the web resource AFTER Save of the record.

When exactly are the events registered on the 'OnSave' of a form triggered?
Are they triggered prior to save or after the save of the record? Where do I specify this?

Thanks in advance!

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Hemant Kumar Sahu Profile Picture
    1,829 on at

    Hi Shidin,

    Created a function (eg. onAfterSave) and call his function on ModifiedOn change event.

    So when ever you save record Modifiedon field gets updated. You may use below code to refresh your page:

    Xrm.Page.data.refresh();

    or

    var name = Xrm.Page.data.entity.getEntityName();

    Xrm.Utility.openEntityForm(name, GuidOfRecord);

    Hope this will help you!!

    Thanks

    Hemant

  • Verified answer
    Biplab Singha Profile Picture
    on at

    Hi Shidin,

    The normal behaviour of CRM is it use to Cache web resource on Form Load so after Save when onload method use to fire it skips the Webresource load . So if you want to reload the web Resource I will suggest you use Below javascript Method and call it on onlaod then it will force the web resource to refresh

    function refreshWebResArea() {

    var webResArea = Xrm.Page.ui.controls.get("WebResource_Name");

    webResArea.setSrc(webResArea.getSrc());
    }

  • Shidin Haridas Profile Picture
    3,499 on at

    Hi Hemant,

    Thank you for your response.

    You are right, I should attach my event to the 'Modified On' date change event if i want it to be triggered AFTER the save of the record.

  • Shidin Haridas Profile Picture
    3,499 on at

    @Biplab,

    This does indeed solve the issue, Thank you so much! :D

  • Community Member Profile Picture
    on at

    Hi Hemant Kumar Sahu

    I am in a similar position as well and this is very helpful but i just have one question. I only want to trigger the after on save function when the record is created. So could i place the trigger point on Created On field instead of the Modified On field to stop this triggering every time it is saved and only on the initial save event? If not and i have to trigger it on the Modified On field, will the getFormType() function still return 1 for a create form so i can filter out when it will get triggered?

    Thanks in advance

  • Suggested answer
    Hemant Kumar Sahu Profile Picture
    1,829 on at

    Hi Brad.Sturgess,

    Yes, you can trigger your method on Create On change event, that should work.

    Please comment if you need any help.

    Thanks

    Hemant

  • Community Member Profile Picture
    on at
  • Suggested answer
    Kjeld Poulsen Profile Picture
    180 on at

    For version 9 onprem, and for unified interface above code will not work, because setting the src on webresource to same value as now will prevent the refresh, so you first need to set it to something else

    Instead of listen to onSave, that will fire before the save event actually happens, i listen on modifiedon changed...

    You get the "Page" object in below by parsing the execution context to your on load;

    // in the onload method

    Page = null;

    function onLoad(executionContext) {

      Page = executionContext.getFormContext();

      Page.getAttribute("modifiedon").addOnChange(updateIframe);

    }

    function updateIframe() {

               var myFrame = Page.getControl("WebResource_mypage");

               var src = myFrame .getSrc();

               myFrame.setSrc("about:blank");

               setTimeout(function() { myFrame.setSrc(src)  },100);

    }

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans