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)

Custom Scripting in Turbo Forms

(0) ShareShare
ReportReport
Posted on by

Hi,

I'm using CRM Online 2016 v8.1, 

Before using Turbo Forms I was able to manipulate the DOM (I know it's not supported), but now I'm not able to reference any object of the form, to check what I can/can't do I did the following function: 

function aaa() {
try {
console.log($(parent.document).find("#contentIFrame0")[0].contentDocument.head);
} catch(err) {
console.log(err.message);
}
try {
console.log($(document).find("#contentIFrame0")[0].contentDocument.head)
} catch(err) {
console.log(err.message);
}
try {
console.log(Xrm.Page.getControl("contentIFrame0").getObject())
} catch(err) {
console.log(err.message);
}
}

This is what I get in the browser console:

Cannot read property 'contentDocument' of undefined
Cannot read property 'contentDocument' of undefined
Cannot read property 'getObject' of null

Is there a way (supported or not) which allows me to reference the HTML obj in TurboForms?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Rajkumar Rajaraman Profile Picture
    on at

    Switched off new rendering engine from below setting and test unsupported code

    Settings -> Administration -> System Settings -> General -> Use legacy form rendering

    Refer the following link:

    community.dynamics.com/.../turbo-forms-with-new-form-rendering-engine

    Hope this helps

    Regards

    Rajkumar Rajaraman

    "Please verify my answer if you found useful"

  • Community Member Profile Picture
    on at

    [quote user="Guido Preite"]

    you need to rewrite the functionality using only supported customization, you are with CRM Online, when your instance will be upgraded to Dynamics 365, all that unsupported JS will stop to work and you can't disable Turbo Forms

    [/quote]

    Thank you for your answer, but I would like to have some more information

    I know that with the next major update I shouldn't be able to deactivate TurboForm, the supported method to get the Iframe HTML obj should be:

    Xrm.Page.getControl("IframeName").getObject()

    At the moment this returns: Cannot read property 'getObject' of null, so the function is not able to find the iframe

    I tried to use every variant I know (supported or not) to get that obj reference but the result is the same: Cannot read property 'xxx' of null or null

    let's say that I want to do this in the suggested (supported) way.

    Am I using the right function ? Am I missing a security setting ? Is it possible to get HTML obj reference of an Iframe inside a Form which uses Turbo Forms to be rendered ?

  • Community Member Profile Picture
    on at

    Hi Giovanni,

    Xrm.Page.getControl("IframeName") is the correct way to get a reference.

    I hope you have made sure that the iframe name is correct.

    Are you executing the code from a custom JavaScript (js) file. Or are you trying to execute it from browser console window?

    Regards,

    Charmis

  • Community Member Profile Picture
    on at

    [quote user="Charmis Varghese"]

    Xrm.Page.getControl("IframeName") is the correct way to get a reference.

    I hope you have made sure that the iframe name is correct.

    Are you executing the code from a custom JavaScript (js) file. Or are you trying to execute it from browser console window?

    [/quote]

    I took the Iframe name directly from the HTML, in my case the name (and also the Id) is "contentIFrame0", the function is executed inside a custom JS which is attached to the module, then the function is executed on module Onload event, I also tried to use it in the browser console and it returns null, I'm using Turbo forms so the script is executed inside a child Iframe (CustomScriptFrame) of the form Iframe.

    Do I need to add something more in this case ?

  • Community Member Profile Picture
    on at

    [quote user="Guido Preite"]

    getControl().getObject() works only for IFRAME added from the form editor and inside the getControl you need to put the name you defined inside the form editor, you can't use getControl to reference other iframe loaded by CRM

    [/quote]

    Thank you, that explains why is not working as I thought. There is a way (supported or not) to reference the form Iframe created by the CRM?

  • Verified answer
    Community Member Profile Picture
    on at

    Hi Giovanni,

    There is no supported way to access an IFrame which is not inside a CRM  form.

    But there is unsupported way:

    // To access the iframe
    top.document.getElementById('contentIFrame1');
    
    //To access the body inside iframe
    top.document.getElementById('contentIFrame1').contentWindow.document.body;
    
    //To access an element named containerLoadingProgress inside the iframe
    top.document.getElementById('contentIFrame1').contentWindow.document.getElementById('containerLoadingProgress');

    As Guido mentioned, please be aware that unsupported code may break in future versions.

    Regards,

    Charmis

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