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 always show related entity (Documents) tab on Main Form?

(1) ShareShare
ReportReport
Posted on by 293

There is no OOB functionality to show the Documents tab:

pastedimage1612532631025v1.png

Is there some approach to always show the Documents tab using JS?

Using the Power Platform editor to show a subgrid is not an option becuase it does not show folder structures.

I have the same question (0)
  • Suggested answer
    Wahaj Rashid Profile Picture
    11,321 on at

    Hi,

    Thank you for your query.

    It is supported in Wave 2 release but only for (Account, Contact, Lead and Opportunity entity):

    https://www.marksgroup.net/blog/dynamics-365-related-documents-now-display-on-records-main-form/

  • KVa Profile Picture
    293 on at

    Thank you! Unfortunately, this approach does not show the folder structure inside the linked location

  • Verified answer
    Wahaj Rashid Profile Picture
    11,321 on at

    Hi,

    I found a hack to show the Documents tab on Load of the form.

    The idea is register an onLoad function to setFocus() on the Documents navigation item, this opens the Documents tab automatically. Furthermore, if you need to show the default tab, you can set the focus to default tab. This way Documents tab is opened but navigation is set to main tab.

    I registered following code on the load of Account entity:

    function openNav(executionContext) {
    
    // get formContext
    
    var formContext = executionContext.getFormContext(); 
    
    // Get Nav. Item
    
    var navItem = formContext.ui.navigation.items.get("navSPDocuments");
    
    
    // First set focus on Nav. Item to open related tab
    navItem.setFocus();
    
    
    // get Main tab (optional)
    var mainTab =  formContext.ui.tabs.get("SUMMARY_TAB");
    
    // Then move to Main Tab
    mainTab.setFocus();
    
    }

    Please see my blog for detailed steps:

    https://crmlogs.wordpress.com/2021/02/07/dynamics-365-ce-show-documents-tab-by-default/

  • KVa Profile Picture
    293 on at

    It's a hack, but it works, thank you. There is a method "setVisible" on the navigation item, but unfortunately it does not show the tab, you really have to change the focus.

  • Ashleigh Swayn Profile Picture
    5 on at

    The subgrid is actually an option because you can use script to change the view to the Document Associated Grid that has the folders. Use a script to simply change the view to the Document Associated Grid and then move back to main tab (similar to the end of Wahaj's script). The advantage of the subgrid on its own tab is that you can name the tab (instead of "Documents"), position it where you want it ("Documents" is always in the far right position). The "Documents" tab also has a disadvantage in that if you click on another related tab you lose the documents tab, plus the view takes up a lot more screen space when compared to using a tab with the subgrid.

  • Aneeqa Pervaiz Profile Picture
    240 on at

    Hello Wahaj Rashid

    I am trying this out on a custom entity, it does not seem to work. For one, it opens up the form with the document associated tab as the main focus, and then also gives the pop up that the script has encountered an error - which is that the mainTab is null. The only change I have done here is to change the name of the main tab, replacing "Summary_Tab" in your case to the name of the main tab, which is "Main" in my case. Registered the script on form onLoad. Is there anything I am missing?

  • Suggested answer
    Frank Lee Profile Picture
    4,617 on at

    Here is a write up to set the Files tab to both custom entity/table or out of the box entity/table that may not have the Files tab by default:

    How to Add SharePoint Document Files Tab to a Dynamics 365 Custom or Out of the Box Table (Entity) Main Form

  • Community Member Profile Picture
    on at

    It gives me the following error:

    TypeError: Cannot read properties of null (reading 'setFocus')
    at Object.LockUnlockFieldsMainOther (crm-dev.axiscapital.com/.../Contact.js:548:21)
    at Object.LoadForm (crm-dev.axiscapital.com/.../Contact.js:267:29)
    at il.executeFunction (crm-dev.axiscapital.com/.../app.js
    at il.execute (crm-dev.axiscapital.com/.../app.js
    at crm-dev.axiscapital.com/.../app.js
    at i (crm-dev.axiscapital.com/.../app.js
    at V._executeIndividualEvent (crm-dev.axiscapital.com/.../app.js
    at V._executeEventHandler (crm-dev.axiscapital.com/.../app.js
    at Object.execute (crm-dev.axiscapital.com/.../app.js
    at w._executeSyncAction (crm-dev.axiscapital.com/.../app.js

    I'm sure that all the naming's are correct but it still gives me this error.

  • KVa Profile Picture
    293 on at

    It seems your navItem variable is null. This occurs because no navigation item for "navSPDocuments" is found. Did you enable Document Management in your entity? You can check by trying to open the Document Management manually. Alternatively, inspect the contents of items:

    Xrm.Page.ui.navigation.items.forEach(e => console.log(e))

  • NL-06071726-0 Profile Picture
    3 on at
    Really good responses. I'm posting a script that combines several answers, mostly from @Ashleigh Swayn and @Wahaj Rashid. This script opens a custom documents tab as Ashleigh suggested and also expands the native audit tab:
     
    this.expandedTabs = function (executionContext) {
        let formContext = executionContext.getFormContext();
        const navigations = formContext.ui.navigation.items;
        const tabs = formContext.ui.tabs;
    
        // Save reference to the currently expanded tab
        const focusedTab = tabs.get().find(tab => tab.getDisplayState() === 'expanded');
    
        // Ensure the "Audit History" navigation item exists
        const auditNav = navigations.get("navAudit");
        if (auditNav) {
            auditNav.setFocus(); // Set focus on the Audit History navigation item
        } else {
            console.warn("Audit navigation item not found.");
        }
    
        // Expand the Audit History tab
        const auditTab = tabs.get("auditHistoryTab");
        if (auditTab) {
            auditTab.setDisplayState("expanded"); // Expand the Audit History tab
        } else {
            console.warn("Audit History tab not found.");
        }
    
        // Expand the Documents tab
        const documentsTab = tabs.get("documents");
        if (documentsTab) {
            documentsTab.setDisplayState("expanded"); // Expand the Documents tab
        } else {
            console.warn("Documents tab not found.");
        }
    
        // Restore focus to the original tab (if it exists)
        if (focusedTab) {
            focusedTab.setDisplayState("expanded");
        } else {
            console.warn("No previously focused tab found.");
        }
    };
    
     

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
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 74

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans