control.getContentWindow() method in Dynamics 365/ PowerApps can help you get formContext in your webresource page. And in-fact a wide range of possibilities. Have you explored it yet?

Recently I bumped into this method and it unraveled before me a wide range of possibilities. And one of them is the perennial problem to access formContext in webresources embedded inside your form.

So let’s see how you can do this.

First things first – getContentWindow() method only works on webresources and iframes. In this example I am going to use a HTML webresource embedded on the form.

On the contact form I am embedding a webresource with the below content.


Quite basic but observe for the method – setFormContext

We will come to this method in a moment. As a next step, on the form load of the contact entity I register the below function.

function contactFormLoad(e) {
    var wrName = ‘WebResource_embedded’;
    var formContext = e.getFormContext();
    var wrControl = formContext.getControl(wrName);
    if (wrControl) {
          function (contentWindow) {
             contentWindow.setFormContext(formContext, Xrm);


The important part I have already highlighted in yellow. As you can see I am using the getContentWindow() method to access the WebResource and then invoke it’s setFormContext method. And what more I am passing both the Xrm context as well as the formContext.

Cool isn’t it. What an easy way to access the contentDocument methods. Similarly you can access other webresource page methods from the entity form. Now when I load the form, the code executes and set’s the formContext in the HTML webresource.

To test this, I use developers tool and navigate to the webresource frame.


And it just works fine. Cool isn’t it?

Hope this helps! Follow my blog to learn more cool stuffs about Dynamics 365 and PowerApps.

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit or reach out to us at

Our product offerings:

CRM-Sharepoint Attachment uploader and metadata manager (

Notes Manager (

Role based views for Dynamics 365 (

Record Cloner for Dynamics 365 (

Published by


I am a Dynamics CRM Most Valuable Professional (MVP) with 12 years of experience in Microsoft .NET Technologies and 9 years of dedicated experience in Microsoft Dynamics CRM. I have worked with companies like Microsoft, SanDisk, PwC, TMF Group and have extensive experience of implementing complex CRM solutions from both offshore and client side. Currently the face of with significant experience in delivering corporate training on Dynamics CRM and have already delivered multiple projects to client through Author of multiple tools on codeplex including the 'Role Based Views' and 'CRM-Sharepoint Metadata manager & Attachment Extractor' which are available for commercial use under For consulting/ training, drop me a note at or visit our website

2 thoughts on “control.getContentWindow() method in Dynamics 365/ PowerApps can help you get formContext in your webresource page. And in-fact a wide range of possibilities. Have you explored it yet?”

    1. Hi Nataraj,

      Thanks for your comments and reading my blog. Does the name of the function really matter. It can be anything I believe. The critical part is getting the contentWindow which is basically the webresource window. Once you get it, you can access any method declared within the webresource. The name I guess really doesn’t matter.

      Please correct me if I am wrong!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s