Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

How to call form script function from iframe html resource?

Posted on by 338

I have the opportunity form script with a function.

On the form I have also embedded an htm resource in an iframe.

From the iframe javascript I want to call a function on the opportunity form script.

How can I achieve that?

  • Suggested answer
    Fedorov Profile Picture
    Fedorov 338 on at
    RE: How to call form script function from iframe html resource?

    Based on the example you posted I created my own function that works better (but not 100% perfect yet)

    Since I know that I have a namespace with name "releye" in the form script I iterate the frames in window.parent until I find that namespace and then I call this frame. I noticed that sometimes the frame had different indexes and therefore the code needed some adjustments..

    getParentFrame().myMethod();

    function getParentFrame() {

               let frame = null;

               for (var i = 0; i < window.parent.frames.length; i++) {

                   try {

                       let releye = window.parent.frames && window.parent.frames[i] ? window.parent.frames[i].releye : null;

                       if (releye && releye != undefined) {

                           frame = window.parent.frames[i];

                           break;

                       }

                   }

                   catch(e)

                   {                    

                       if (e.message)

                           throw e.message;

                       else

                           throw e;

                   }

               }

               return frame;

           }

  • Suggested answer
    Fedorov Profile Picture
    Fedorov 338 on at
    RE: How to call form script function from iframe html resource?

    The article helped me find a solution even though it didn't exactly as proposed there. (sort of)

    For me (Unified Interface) the following worked:

    OPPORTUNITY FORM

    someFunction = function () {  // Do stuff }

    HTM WEB RESOURCE in Iframe

    function someting() {  window.parent.frames[0].someFunction(); }

  • Suggested answer
    Adrian Begovich Profile Picture
    Adrian Begovich 21,009 Super User 2024 Season 2 on at
    RE: How to call form script function from iframe html resource?

    Hi Fedorov,

    This article explains how to call JavaScript functions defined in Microsoft Dynamics CRM forms from an IFRAME.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans