Skip to main content

Notifications

Announcements

No record found.

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,

  • Avinashmane25 Profile Picture
    30 on at
    RE: How to access formContext/executionContext in Html webresource file without passing parameter.

    Hi @Susritha,

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

  • Suggested answer
    CVO Profile Picture
    77 on at
    RE: How to access formContext/executionContext in Html webresource file without passing parameter.

    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. 

  • LeoAlt Profile Picture
    16,331 Moderator on at
    RE: How to access formContext/executionContext in Html webresource file without passing parameter.

    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

  • Susritha Profile Picture
    195 on at
    RE: How to access formContext/executionContext in Html webresource file without passing parameter.

    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
    RE: How to access formContext/executionContext in Html webresource file without passing parameter.

    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

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 51 Most Valuable Professional

#2
Ramesh Kumar Profile Picture

Ramesh Kumar 42

#3
David Shaw_UK Profile Picture

David Shaw_UK 27

Featured topics

Product updates

Dynamics 365 release plans