Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Form automatically scrolls to Iframe

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

  • Filip Vanchevski Profile Picture
    Filip Vanchevski 215 on at
    RE: Form automatically scrolls to Iframe

    Hi Alex if you are using the same code just try and call the function as a parametar for the SetTimeout() function which you can do in Javascript, the SetTimeout function is native to javascript so it's already pre loaded and ready for you to use.

    If you need more information about SetTimeout try the following link -> https://www.w3schools.com/jsref/met_win_settimeout.asp

    Good luck and let me know if you made it work.

    [View:https://www.w3schools.com/jsref/met_win_settimeout.asp:750:50]

  • Filip Vanchevski Profile Picture
    Filip Vanchevski 215 on at
    RE: Form automatically scrolls to Iframe

    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.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Form automatically scrolls to Iframe

    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.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Form automatically scrolls to Iframe

    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 

  • Filip Vanchevski Profile Picture
    Filip Vanchevski 215 on at
    RE: Form automatically scrolls to Iframe

    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

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Form automatically scrolls to Iframe

    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);
    }

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Form automatically scrolls to Iframe

    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.

  • Filip Vanchevski Profile Picture
    Filip Vanchevski 215 on at
    RE: Form automatically scrolls to Iframe

    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
    gdas 50,085 on at
    RE: Form automatically scrolls to Iframe

    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.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Form automatically scrolls to Iframe

    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.

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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans