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)

Form automatically scrolls to Iframe

(0) ShareShare
ReportReport
Posted on by 215

Hi guys,

I'm facing a situation where the form automatically scrolls to a iframe that i recently set on the form.

The iframe is displaying share point documents connected to that record. Bellow is the code i used to set the correct URL for the iFrame.

function SetDocumentFrame() {

    //You can see what the url should be by navigating to the 'Documents' area under related records, viewing the page soure
    //and looking for 'areaSPDocuments'. The formid appears to be nothing more than a random guid value and not tied to anything 
    //specific in your org. 

    //Use: Make sure Document Management is enabled for the entity (helps to turn on automatic folder creation)
    //     Add a web resource with this code to the form 
    //     Execute this function during the form's OnLoad event

    var url = Xrm.Page.context.getClientUrl() +
        "/userdefined/areas.aspx?formid=ab44efca-df12-432e-a74a-83de61c3f3e9&inlineEdit=1&navItemName=Documents&oId=%7b" +
        Xrm.Page.data.entity.getId().replace("{", "").replace("}", "") + "%7d&oType=" +
        Xrm.Page.context.getQueryStringParameters().etc +
        "&pagemode=iframe&rof=true&security=852023&tabSet=areaSPDocuments&theme=Outlook15White";
    debugger;
    Xrm.Page.getControl("IFRAME_Documents").setSrc(url); //Replace IFRAME_??? with actual IFRAME name


The code comes from Jason Lattimer's blog and works perfectly but for some reason it makes the form scroll to the iframe.

Any suggestions?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at

    Hi Filip,

    What happens if OnLoad you call a method that sets focus on another field (on top of the form) - msdn.microsoft.com/.../gg334266.aspx

    Does that impact the behavior?

    Regards,

    Radu

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    hmmm weird. You could try to set the focus on the 1st field of your form just after executing this function. Maybe then it won't scroll down.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Philip,

    I am also assuming so, you need to setfocus of the iframe.

    In any case this is not resolved please share screenshot  here.

  • Filip Vanchevski Profile Picture
    215 on at

    Thanks for the suggestions.

    I just tried setting the focus on the first tab .

    function SetFocus() {

       Xrm.Page.ui.tabs.get("SUMMARY").setFocus();

    }

    But i noticed that the scrolling happens after the scripts are executed.

    I checked Restrict cross frame scripting, and that seems to get the job done, but then we are unable of creating new documents from the form, so this option does not work also.

    Next I also tried unchecking the tab option Expand this tab by default, which seemed to work, but when i expand the tab the iframe shows for a second and then its gone, when i saw this i added a function onChange state of the tab, and now the user needs to expand, close and then expand again in order to view the Iframe.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hello Filip,

    I am not sure but is there anything specially which is setting height of the iframe window?.  Just to check with browser F12 window.

    Hope this helps.

  • Verified answer
    Community Member Profile Picture
    on at

    Hi,

    This seems to be related to the recent upgrade to version 9 for my case.

    a quick workaround is to set the focus back to summary tab on tab after the Iframe finished loading after a timeout.

    Call SetFocus in the Iframe event OnReadyStateComplete.

    you can adjust the timeout depending on your loading speed.

    function Show(){
    var control = Xrm.Page.ui.tabs.get("Summary");
    control.setFocus();
    }
    function setFocus(){ 
    setTimeout(Show, 1000);
    }

  • Filip Vanchevski Profile Picture
    215 on at

    The setTimeout did the trick as it gives the Iframe enough time to load and then sets the focus.

    Thank you for your help, answer is now marked as Verified for future reference.

    Cheers, Filip

  • Community Member Profile Picture
    on at

    Dear all, 

    I have just upgraded my system and am encountering the exact same issue. I also l have used Jason Lattimer's code, but am pretty inexperienced with making modifications myself. How would i modify this as suggested to call the subsequent setfocus function and return my user to the top of the page at the summary tab?

    Many thanks,


    Alex 

  • Suggested answer
    Community Member Profile Picture
    on at

    If you're using the onReadyEvent for the iframe you shouldn't need the timeout.

    Using the solution - which did work - I noticed a slight 'jitter' as the Form jumped to the Tab and then back to the top of the Form.

    I made the tab hidden and hid it before the getControl code and then in the onReadyEvent I unhid that tab.  This seems to work without any cosmetic issues at all.  We're D365 v9, using Chrome.

  • Filip Vanchevski Profile Picture
    215 on at

    Hi eps,

    After i posted this, the client also noticed the jitter, and i ended up using a bit of a different approach, i set the Extended by default to false, and i wait until it loads and then expand it.

    For other clients for whom it didn't matter if the tab is opened or closed i simple set the tab to not be expanded by default and does the trick.

    Although you might see other problems when you expand the tab, for example the Actions such as "Create new Word document" etc might not be visible, in that case just reload the IFrame when the user clicks on the tab and you should be good.

    Regards Filip.

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