Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Show/hide tab based on BPF, code error

(0) ShareShare
ReportReport
Posted on by 815

Hi,

I got this below code from the community and has some issue. Issue when lead is created and qualify to convert opportunity then the code does n't work. To work i need to refresh the opportunity page and the code works. But if i directly create opportunity then the code works.

_________________________________________________________________________________________________

//Registered the method in onload 
    function formonload() {
        Xrm.Page.data.process.addOnStageSelected(checkBPF);
        Xrm.Page.data.process.addOnStageChange(checkBPF);
    }

    function checkBPF() {
        var activeStage = Xrm.Page.data.process.getActiveStage();
        var stageId = activeStage.getId();  
        var stagename = activeStage.getName();
        // you can apply your if else logic to show hide the tab, you can use stageid or stagename, depending on your preferences.

        if (stagename == "Discovery") {  //// Its best practice to check condition with ID

            Xrm.Page.ui.tabs.get("Discovery").setVisible(true); //set your tabname here.

            Xrm.Page.ui.tabs.get("Proposal").setVisible(false);//set your other tabname here.

            Xrm.Page.ui.tabs.get("Advocacy").setVisible(false);

            Xrm.Page.ui.tabs.get("Close").setVisible(false);

        }

        else if (stagename == "Proposal") {


            Xrm.Page.ui.tabs.get("Proposal").setVisible(true);

            Xrm.Page.ui.tabs.get("Advocacy").setVisible(false);

            Xrm.Page.ui.tabs.get("Close").setVisible(false);

        }

        else if (stagename == "Advocacy") {


            Xrm.Page.ui.tabs.get("Advocacy").setVisible(true);

            Xrm.Page.ui.tabs.get("Close").setVisible(false);

        }

        else if (stagename == "Close") {


            Xrm.Page.ui.tabs.get("Close").setVisible(true);

        }

________________________________________________________________________________

Can you pl help where could be the issue ? }

*This post is locked for comments

  • Syed_Faisal Profile Picture
    Syed_Faisal 815 on at
    RE: Show/hide tab based on BPF, code error

    Thanks a lot Gowtham and Ravi,

    added code now works fine after Qualifying lead to opportunity.

    Regards

    Faisal

  • Verified answer
    gdas Profile Picture
    gdas 50,089 on at
    RE: Show/hide tab based on BPF, code error

    Hi Sayed ,

    when you are writing below code its basically attached the event only  in the onload and the event which actually trigger at the time of StageSelected and StageChange. So you have to call separately the show/hide functionary based on current selected stage .

       function formonload() {

           Xrm.Page.data.process.addOnStageSelected(checkBPF);

           Xrm.Page.data.process.addOnStageChange(checkBPF);

       }

    Your code should be like below -

       function formonload() {

           Xrm.Page.data.process.addOnStageSelected(checkBPF);

           Xrm.Page.data.process.addOnStageChange(checkBPF);

            checkBPF();

       }

  • Verified answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: Show/hide tab based on BPF, code error

    Hi,

    you are dealing with cross entity, thus register checkBPF in onload event too.

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Show/hide tab based on BPF, code error

    Hi,

    Try calling checkBPF on load as well.

    =============

    function formonload() {

           Xrm.Page.data.process.addOnStageSelected(checkBPF);

           Xrm.Page.data.process.addOnStageChange(checkBPF);

    checkBPF();

       }

    =============

    Hope this helps.

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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,309 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans