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

  • Community Member Profile Picture
    on at
    RE: Create iframe dynamically in Dynamics 365 (CRM DOM problem)

    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 in appSource, this means that iframe need to add dynamically to all this custom entities, but I can not access to they). Last time this worked by adding iframe to DOM via script, but now this ability locked. (via javascript)

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Create iframe dynamically in Dynamics 365 (CRM DOM problem)

    What is the reason to create dynamic iframes when you can deal with OOB functionality?

    If you need more iframe you could create 3-4 iframe (and show-hide them according to needs).

    I discourage to implement "on the fly" dom elements: its hard do deal with them and every update you are "under the gun".

    Please let me know.

    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
    RE: Create iframe dynamically in Dynamics 365 (CRM DOM problem)

    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.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Create iframe dynamically in Dynamics 365 (CRM DOM problem)

    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
    RE: Create iframe dynamically in Dynamics 365 (CRM DOM problem)

    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).

  • Syed Ibrahim Profile Picture
    6,257 on at
    RE: Create iframe dynamically in Dynamics 365 (CRM DOM problem)

    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
    RE: Create iframe dynamically in Dynamics 365 (CRM DOM problem)

    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
    RE: Create iframe dynamically in Dynamics 365 (CRM DOM problem)

    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
    RE: Create iframe dynamically in Dynamics 365 (CRM DOM problem)

    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.

  • Aric Levin Profile Picture
    30,188 Moderator on at
    RE: Create iframe dynamically in Dynamics 365 (CRM DOM problem)

    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.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,865 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,723 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans