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