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)

Create iframe dynamically in Dynamics 365 (CRM DOM problem)

(0) ShareShare
ReportReport
Posted on by

Hi there! 

I have a problem!

Via custom button script I create iframe:

	var frame = window.top.document.createElement('iframe');
	frame.setAttribute("src", src);
	frame.setAttribute("id", "mainIframe");
	frame.setAttribute("allowtransparency", "true");
	frame.setAttribute("style", "background:none transparent; position:absolute; border:none; top:50px; left:0; width:100%; height: calc(100% - 50px);");
	window.top.document.body.appendChild(frame);

In this iframe I open webresource html.
But I cannot publish to appSource my solution, because I cannot "Directly accessing the HTML Document Object Model (DOM) elements of a Dynamics 365/CRM application page or entity form is not supported in any version and presents a considerable supportability risk". Is exist way to create it (iframe) dynamically? Via Xrm... or something else?  

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    would recommand you to add an iframe on the desired form and hide it. When the user is clicking the button it will show the Iframe on the form and you then can pass the different parameters that you want to give it.

  • Syed Ibrahim Profile Picture
    6,257 on at

    You can create an html web resource and can use it as an iframe in the crm or you can open the html using button click.use the below code to open html web resource.

    alagunellaikumar.blogspot.sg/.../open-html-page-when-button-click-in-crm.html

    But I have no idea why u want to create the iframe dynamically

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    As Syed mentioned, not sure why you want to do this dynamically, but the best approach would be either to create a web resource or IFRAME on the form inside a section and hide the section, so that it is not visible on the form.

    When you need it just make that section on the form visible and set the src property of the iframe (or web resource).

    Hope this helps.

  • Community Member Profile Picture
    on at

    I can add the iframe to some forms, but initially I do not know what entities will be, on each organization - different (including custom). therefore I want to dynamically create. and iframe - because I want the integration built into the CRM window.

  • Syed Ibrahim Profile Picture
    6,257 on at

    If you are not sure about entities then how will you pass or get data from entities ?. It's advisable to have it in form

  • Community Member Profile Picture
    on at

    I can get entity id and entity name and pass it as parameters to webresource in iframe.

  • Syed Ibrahim Profile Picture
    6,257 on at

    but still you will be passing info from entity right. Its good to be defined for which entity you creating iframe. So we no need to create some dynamics . Accessing DOM is not supported way.Upon new releases there will be change in the client side access model so It is not advisable to create any business logic using DOM.

    Hope this helps. Pls mark it as Answered/Verified to close the thread if suggestion resolved your query

  • Community Member Profile Picture
    on at

    Why no need to create some dynamics iframes? I added button via ribbon workbench. And she was applied to all crm entities(with condition). But after clicking on this button I need to load CRM web resource in iframe located on the form (not in new window). But customer can have different custom entities (I publish solution for different customers). I can not add iframe there (not dynamically). But maybe exist way to add global IFrame on all entities forms (by something).

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Konstantin,

    i writed for you the following code:

    function CalledByRibbonButton1()
    {
        var entityid = Xrm.Page.data.entity.getId();
        var entityname = Xrm.Page.data.entity.getEntityName();
        var url = "http://someurl";
        SetIFrame(url, entityname, entityid);
    }
    
    function CalledByRibbonButton2() {
        var entityid = Xrm.Page.data.entity.getId();
        var entityname = Xrm.Page.data.entity.getEntityName();
        var url = "http://someotherurl";
        SetIFrame(url, entityname, entityid);
    }
    
    function SetIFrame(url, entityname, entityid)
    {
        var theiframe = Xrm.Page.ui.controls.get("IFRAME_TheIFrame");
    
        if (url) {
            var params = "?name=" + entityname + "&id=" + entityid;
            var target = url + params;
            theiframe.setSrc(target);
        }
    }

    If you need more help dont hesitate to ask.

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Community Member Profile Picture
    on at

    Hello! It is good, but it not creates iframe dynamically!

    Necessary condition for this to work is an already existing Iframe on the form, which need to add by hands.

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