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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Service | Customer Service, Contact Center, Fie...
Suggested Answer

How to access formContext/executionContext in Html webresource file without passing parameter.

(0) ShareShare
ReportReport
Posted on by 195

Hi,

Can anyone please tell me  How to access  formContext/executionContext in  Html webresource file without passing parameter.

Thanks in advance!!.

Regards,

Susritha,

I have the same question (0)
  • LeoAlt Profile Picture
    16,331 Moderator on at

    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.

    https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/284186/how-to-pass-the-execution-context-to-crm-html-webresource-in-dynamics-365-v9

    https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/webpage-html-web-resources

    Best Regards,

    Leo

  • Susritha Profile Picture
    195 on at

    Hi Leo,

    I can use window.parent.Xrm, but Xrm.Page is deprecated.

    So, we are replacing Xrm.Page with executionContext.getFormContext();

    Regards,

    Susritha

  • LeoAlt Profile Picture
    16,331 Moderator on at

    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

  • Suggested answer
    CVO Profile Picture
    77 on at

    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. 

  • Avinashmane25 Profile Picture
    30 on at

    Hi @Susritha,

    Where you want to pass FormContext into Single HTML page or inside form HTML page.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
FSRon Profile Picture

FSRon 59

#2
James White Profile Picture

James White 21

#3
AT-28040446-0 Profile Picture

AT-28040446-0 20

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans