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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Call function on load from inside HTML web resource

(0) ShareShare
ReportReport
Posted on by

I have an html web resource on a form that contains an iframe. The reason the iframe is in an html web resource is because I need to capture the record guid after the record is created in order to include said guid in the iframe URL. What I need to do is only show the iframe after the user creates the record. I figured I'd do this by checking the form type of the record, and if the form type is "2" (or really anything except "1" which is type create) than I'd show the iframe. I have the code to do this between script tags on my html web resource. I call my function onload of the <body>. Initially, I figured this would fire even after a save because if I include javascript web resource calls on load in the form properties, they execute after a save. Apparently, however, the body of the html web resource does not load again after a save? 

I'm wondering if I'm missing something obvious here, or if there is a way to accomplish what I am trying to accomplish. I'd be happy to clarify my question(s) if it's confusing. Thanks for any help. 

*This post is locked for comments

  • Verified answer
    M I Mostafa Profile Picture
    on at
    RE: Call function on load from inside HTML web resource

    Hi there,

    The normal behaviour of Dynamics 365 is that it caches the web resource on Form Load so after you click Save, the onload method used to fire it skips the Webresource load.

    A good option is to create a function (for example: onAfterSave) and call this function on the ModifiedOn change event.

    So every time you save a record, the Modifiedon field will change and then fire your JavaScript function to to refresh your page. You can use any of the following JavaScript code to refresh:

    Xrm.Page.data.refresh();

    or

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

    Xrm.Utility.openEntityForm(name, GuidOfRecord);

    Hope this helps! Please mark as verified answer if you found this response helpful.

  • Verified answer
    Nithya Gopinath Profile Picture
    on at
    RE: Call function on load from inside HTML web resource

    Hi,

    You could write the following Javascript function on save of the form so that the web resource gets refreshed on save. Hence on every save of the form, the body on-load function of the web resource will be fired.

    function RefreshWebResource() {
        var webResourceControl = Xrm.Page.getControl("WebResource_Name");
        var src = webResourceControl.getSrc();
        webResourceControl.setSrc(null);
        webResourceControl.setSrc(src);
    }

    Hope this helps.

  • fishyjj Profile Picture
    on at
    RE: Call function on load from inside HTML web resource

    Thanks for your reply. This is a very good idea, and a general method I use on some other forms. I recently came to realize that this method doesn't work when a user fills in all the necessary fields and clicks "Save & Close" - Do you have a way that solves for this issue?

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans