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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Xrm.Page.getControl('WebResource').getObject().contentWindow.document Error in Unified Interface

(0) ShareShare
ReportReport
Posted on by 210

I have a external HTML web resource which is placed onto contact form. During the on-load event of contact form, the below statement of the code does not work ( it should alert the HTML document object)

it throws an error as below.

Unable to get property 'contentWindow' of undefined or null reference

function Contact_OnLoad() {

    showHidePostalAddressWebResource();

}

Function showHidePostalAddressWebResource(){

var htmlcontent = Xrm.Page.getControl('WebResource').getObject().contentWindow.document;

alert(htmlcontent);

}

it only happens in Unified Interface not in Web Client. Can anyone please suggest any alternative statement for above code ? 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    Accessing the dom object is not supported so no surprise that its not working. What exactly are you trying to achieve?

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    As  Ravi already mentioned , that this is not supported. However did you tried executing below line whether object is getting or not ?

    Xrm.Page.getControl('WebResource_name').contentWindow;

  • Suganthar_Satkunam Profile Picture
    210 on at

    Thanks Ravi. I want to make invisible the HTML web resource's all the fields based on one field (SameAsAddressCheckbox) changes in contact form. See the complete javascript as below

    function Contact_OnLoad() {

       showHidePostalAddressWebResource();

    }

    function showHidePostalAddressWebResource() {

       var SameAsAddressCheckbox = Xrm.Page.getAttribute("addresssameasresidential").getValue();

     

    //access the Postal Address field

      var htmlcontent = Xrm.Page.ui.controls.get('WebResource_ContactPostal').getObject().contentWindow.document; 

      alert(htmlcontent);

      //var htmlcontent = Xrm.Page.getControl('WebResource_ContactPostal').getObject().contentWindow.document;

       if (htmlcontent.getElementById("allfields") != null) {

           if (SameAsAddressCheckbox) {

               htmlcontent.getElementById("allfields").style.visibility = "hidden";

               htmlcontent.getElementById("addline1").value = null;

           }

           else {

               htmlcontent.getElementById("allfields").style.visibility = "visible";

           }

       }

       else {

           setTimeout(showHidePostalAddressWebResource, 500);

       }

    }

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    why dont you put the checking (JS) inside the html, while the form field changed, call the html again, and show hide the fields in html based on the form field value. You can avoid to use unsupported code in this case.

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Agree with Alex, instead of doing the show hide from crm script, perform the show hide within the HTML.

    Also, it is always better to just try it with simple field and simple logic instead of building the complex logic...try that if doesn't work, share the sample code here to assist further.

  • Suganthar_Satkunam Profile Picture
    210 on at

    @Goutam I got the undefined

  • Suganthar_Satkunam Profile Picture
    210 on at

    Hi Ravi and Alex, The Issue is that HTML webresource is third party one and will be replaced every time when we upgrade or change the solution.
    Is there no other alternative ways of doing this other than this ?

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    I don't thik there is any supported way but if this is your requirement, I will see if this can be achieved. So just to confirm, you have a HTML web resource embedded in a contact form and you want to retrive the fields from that HTML using the CRM script (on load)?

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    Please try this link-

    stackoverflow.com/.../get-element-from-within-an-iframe

    Hope this helps.

  • Suganthar_Satkunam Profile Picture
    210 on at

    Yes Ravi that is a requirement

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans