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 365 | Integration, Dataverse...
Answered

How to call form script function from iframe html resource?

(0) ShareShare
ReportReport
Posted on by 40

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?

I have the same question (0)
  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 Moderator on at

    Hi Fedorov,

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

  • Suggested answer
    Fedorov Profile Picture
    40 on at

    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
    Fedorov Profile Picture
    40 on at

    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;

           }

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 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 58 Most Valuable Professional

#2
#ManoVerse Profile Picture

#ManoVerse 42

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 38 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans