Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Run JavaScript on all Navigation

Posted on by Microsoft Employee

I have a requirement to render an external view within CRM an use the most page real estate possible. In order to achieve this I have a web resource which manipulates the DOM and then changes the source address of the iframe within #contentIFrame0 to the address of my view. The issue is that when I navigate to any other view, my DOM changes are still in effect. Namely, #crmTopBar, #formHeaderContainer and #formFooterContainer  are hidden and #crmContentPanel is still higher on the screen than it should be.

Script excerpt:

$(window.parent.parent.document.getElementById('crmTopBar')).hide();
$(window.parent.document.getElementById('formHeaderContainer')).hide();
$(window.parent.document.getElementById('formFootersContainer')).hide();
$(window.parent.parent.document.getElementById('crmContentPanel')).css('top', '50px');
$(window.parent.document.getElementById('mainContainer')).css('left', 0).css('max-width', 'unset');
$(window.parent.document.getElementById('tdAreas')).css('height', $(window.parent).height());

Is there a global from change or navigation change event that I can modify and add script to which will revert my DOM changes when navigating away from my new UI?

Things that don't work:

targeting #contentFrame0 to render my new view: this seems to break navigation entirely

modifying the webResource which I use for navigating to other pages: since the other forms are already loaded, this script does not run again if I go back to a previously loaded screen

*This post is locked for comments

  • Pieter H Profile Picture
    Pieter H on at
    RE: Run JavaScript on all Navigation

    Hi Zachariah, did you find a good working solution which preferably is supported? I have here a similar requirement and looking for a solution. I did found out that the MS Unified Service Desk (USD) has a configurable option to hide the navigation or command bar... See the documention at: msdn.microsoft.com/.../dn864949.aspx

    Unfortunately for me unclear how it was implemented.

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Run JavaScript on all Navigation

    Hi Zachariah,

    Yes, the sitemap doesn't have the context of the record. To get the context you need to be on the record. With that said, I don't think it is possible to use sitemap to load your external page.

    It has to be inside the record as you may have already tried Iframe/ Web Resource but then this will add the form header & footer.

    I am not sure if this is feasible but you could try creating a external page (asp.net web page) and load it in sitemap. In this page, display all the accounts such that user selects the account followed by your current logic.

    Sorry I don't have exact answer for your questions :(.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Run JavaScript on all Navigation

    Correct me if I'm wrong:

    A site map component does not have context (in my case, accountId)

    A navigation property can't be displayed without the other form elements (header, footer, top bar)

    If either of those two assumptions is bad I might still have a chance :)

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Run JavaScript on all Navigation

    Thanks Ravi,

    If I open the external URL directly, is there 1) a way to pass accountId to the external URL (we are currently handling this with some JavaScript in a web resource file)  and 2) is there a way to render with the CRM masthead or will I lose that context?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Run JavaScript on all Navigation

    Thanks Mir,

    The requirement I have is to maintain the CRM masthead and context and render the new view below. I can use an html file as a web resource, but in the context of an account it renders in an iframe in the middle of the page, and the command bar and form headers and footers are present which the business says is not acceptable. Is there any way to render my view using the full page height instead of inside the iframe?

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Run JavaScript on all Navigation

    Hi zFournier,

    This is unsupported which is why the things have stopped working. Even if you figure out the way to change the DOM, there is no guarantee that it will continue to work with the future release.

    There must be some supported way to achieve your requirement. You could open the external URL directly using sitemap.

    Hope this helps.

  • Mir Hassan Ali Profile Picture
    Mir Hassan Ali 1,720 on at
    RE: Run JavaScript on all Navigation

    Hi

    Instead of changing the CRM UI by manipulating DOM (which is unsupported), why not display the view in your web resource?

    Regards

    Mir

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

Featured topics

Product updates

Dynamics 365 release plans