Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Answered

Javascript example needed - Show Tab when Related Entity contains data

Posted on by

Hi, 
I have a requirement to show the 'Create PO' tab only when the related entity "Work Order" contains a record - else hide. 
Has anyone encountered this example before and have a sample code for me to get started?  Many thanks in advance.  

pastedimage1669132028418v2.png

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,962 Moderator on at
    RE: Javascript example needed - Show Tab when Related Entity contains data

    Hi,

    Good to hear that it worked 

  • Chrisbra22 Profile Picture
    Chrisbra22 on at
    RE: Javascript example needed - Show Tab when Related Entity contains data

    Update.  Got this to work:

    function ShowHideMasterPOMatchPOTabs(executionContext) {

     var formContext = executionContext.getFormContext();

     var isRole = false;

     Xrm.Utility.getGlobalContext().userSettings.roles.forEach(

       role => {

         if(

           role?.name == "System Administrator" ||

           role?.name == "*BF Field Service - Zone Manager" ||

           role?.name == "*BF Field Service - Dispatcher"

         ) {

           isRole = true;

         }

       }

     );

     formContext.ui.tabs.get("tab_4").setVisible(isRole);

    }

  • Chrisbra22 Profile Picture
    Chrisbra22 on at
    RE: Javascript example needed - Show Tab when Related Entity contains data

    Thanks, I did see that article but the code was not working for me.  In the article above the code is hiding all related navigation items if User Security Role is not System Admin.  

    Basically I need the code to show the 'Match PO' Tab (tab_4) only to the roles System Admin (System Administrator), Zone Manager (*BF Field Service - Zone Manager), Dispatcher (*BF Field Service - Dispatcher), else it hides. 
    Any suggestions here?  I've tried and am not successful thus far. 

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,962 Moderator on at
    RE: Javascript example needed - Show Tab when Related Entity contains data

    Hi,

    Please check below link for the sample code

    crmlogs.wordpress.com/.../

  • Chrisbra22 Profile Picture
    Chrisbra22 on at
    RE: Javascript example needed - Show Tab when Related Entity contains data

    Thanks!  Will check that out.  

    Another question is if there is a code snippet to show a tab (tab_4) if User Security Role = ("System Administrator"), ("*BF Field Service - Dispatcher"), (*BF Field Service - Zone Manager"), else hide.

    I have a snippet that is not working I think because the !UserHasRole is not properly being used, or out of date.  

    Any thoughts or sample would be appreciated!  

  • Verified answer
    Bipin D365 Profile Picture
    Bipin D365 28,962 Moderator on at
    RE: Javascript example needed - Show Tab when Related Entity contains data

    Hello,

    Use Xrm.WebApi.retrieveMultipleRecords to check the record count in related entity

    learn.microsoft.com/.../retrievemultiplerecords

    Dataverse Rest builder tool can be used to generate code

    carldesouza.com/.../

  • Chrisbra22 Profile Picture
    Chrisbra22 on at
    RE: Javascript example needed - Show Tab when Related Entity contains data

    Thanks!  I did see some of that documentation.  I have just never wrote code to show/hide tabs based on a related entity having data (as shown in my screenshot above).  I'll keep digging, thanks.  

  • Verified answer
    Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Moderator on at

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,532 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,501 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans