Hi,
Can anyone please tell me How to access formContext/executionContext in Html webresource file without passing parameter.
Thanks in advance!!.
Regards,
Susritha,
Hi,
Can anyone please tell me How to access formContext/executionContext in Html webresource file without passing parameter.
Thanks in advance!!.
Regards,
Susritha,
Hi @Susritha,
Where you want to pass FormContext into Single HTML page or inside form HTML page.
This is an old thread but it is near the top of the search result listings, so I'm just going to put how to do it in here.
There are a number of posts online that mention passing the execution context to an onLoad event and then using contentwindow to call a method in the web resource with the formContext as a parameter.
I've tried this and the formContext is not always passed. Furthermore, navigating on to an entity on the related records tab and navigating back to the original tab causes the Web Resource to reload, but since the onLoad is not run when switching tabs, you need to run the same onLoad on change of tab. And again, it isn't always 100%.
The solution I've used .is to assign the formContext on the onLoad to a var on the top window. Simply do the following:
1: On your forms "onLoad" javascript webresource, put the following code in a function that is triggered on on load of the form (passing in formContext as first parameter):
window.top.formContextForXxxWebResource = executionContext.getFormContext();
2: Now in your HTML web resource, you can simply use the following object as the formContext!
window.top.formContextForXxxWebResource!
Why use window.top and not window.parent? I did use window.parent, but what if Microsoft change the product so that the web resource or the onload event have different parents? window.top will always be the same container, so this will ensures that you won't need to change it in future.
Hope this helps someone out there.
Hi Partner,
Currently we could not use formcontext in html directly without passing parameters, but you could use Xrm.page.
Although it will be deprecated in the future, it is still available now.
Regards,
Leo
Hi Leo,
I can use window.parent.Xrm, but Xrm.Page is deprecated.
So, we are replacing Xrm.Page with executionContext.getFormContext();
Regards,
Susritha
Hi partner,
We could not get formcontext in web resource now, but we could use Xrm.page in html instead.
If the html is a child page of form, you could use "Xrm = window.parent.Xrm;" to get Xrm.
You could also refer to the following threads.
Best Regards,
Leo
Muhammad Shahzad Sh...
51
Most Valuable Professional
Ramesh Kumar
42
David Shaw_UK
27