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 365 | Integration, Dataverse...
Unanswered

getContentWindow is not working when navigating to related section of the form.

(0) ShareShare
ReportReport
Posted on by 25

Hi,

I am using getContentWindow in HTML to access the XRM and Formcontext of the Webresource control

on onload of the form i have wrote below code:

 //Get Quote Group control
                    var QuoteGroupControl = formContext_1.getControl("WebResource_QuoteGroup");
                    //Validate control
                    if (QuoteGroupControl!=null) {
                        //get getContentWindow
                        QuoteGroupControl.getContentWindow().then(function (contentWindow) {
                            //Pass xrm and formcontext
                            contentWindow.setClientApiContext(XrmformContext_1);
                        });
                    }
Now on html page i have added setClientApiContext function
 <script>


        function setClientApiContext(xrmformContext) {

            window.top.gridDirty = false;
            window.top.dataSearching = false;

            $("#splitter").igSplitter({ height: "350px"panels: [{ size: "35%"min: "25%"max: "75%" }] });

            $("#buttonCancel").igButton({
                labelText: $("#buttonCancel").val(),
                height: "33px",
                click: function (e) { window.top.dataSearching = false; }
            });

            window.Xrm = xrm;
            window.formContext = formContext;

            //Start the onload
            onLoad();

        }
    </script>
Now my html loads correctly when navigate between the tabs but when i navigate to related section and come back on html page the html is not loading as i have not written the code in document.onready!
Please can you let me know why this is happening!
I have the same question (0)
  • cloflyMao Profile Picture
    25,210 on at

    Hi Ankita,

    - I have not written the code in document.onready!

    Actually setClientApiContext function of your web resource is executed within the snippet below 

    QuoteGroupControl.getContentWindow().then(function (contentWindow)

        { //Pass xrm and formcontext

            contentWindow.setClientApiContext(Xrm, formContext_1);

        }

    );

    As we see, contentWindow.xxx will run xxx function of iframe web page(web resource is atually an iframe element), it's standard javascript. (I found contentWindow in callback is equal to standard document.getElementsByTagName("iframe")[0].contentWindow)

    So even if you didn't run setClientApiContext by document.onready, the function had been already invoked in QuoteGroupControl.getContentWindow().then callback at form Onload event.

    - when i navigate to related section and come back on html page the html is not loading

    I didn't find any articles which could give an explanation toward it, so below is just my thought:

    The behavior that navigating and switching between different tabs still keep us stay on form, and tabs are part of form(as we can see in legacy web client and form editor.), so web resouce could always work.

    However, open a new tab from "Related" will partially refresh form,(web resource will also refresh when we navigate back to any tab of form.)

    the onLoad event will only happens once when the form is loaded,

    form_onload function won't be executed again due to form is only partially refreshed, thus QuoteGroupControl.getContentWindow().then won't invoke function of the web resouce again, and the HTML was not loading.

    In a word, currently the issue you met is by design.

    Regards,

    Clofly

  • Ankita R. Profile Picture
    25 on at

    Any update on how to resolve this issue! Stuck badly!

  • cloflyMao Profile Picture
    25,210 on at

    Hi Ankita,

    Unfortunately there is no workaround to solve it at present,

    please submit what you have found to Ideas forum to make the issue could be fixed in the future release.

    Regards,

    Clofly

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 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 80

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans