web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Code error for show/hide tab based on BPF

(0) ShareShare
ReportReport
Posted on by 815

Hi,

I got this below code from the community, code is for when changing the BPF stages, Tabs visible.

Now issue when changing the stages, Tab is not getting visible but it is visible only after manually refreshing the whole page. Each time i need to refresh page when moving to next stage. 

Please help !

Below is the code :

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")

{

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

}


}

function formonload()
{
Xrm.Page.data.process.addOnStageChange(checkBPF);
checkBPF();
}

*This post is locked for comments

I have the same question (0)
  • Syed_Faisal Profile Picture
    815 on at
    RE: Code error for show/hide tab based on BPF

    I have updated the code and now it is working fine.

    1 issue i am facing now, First creating a new lead then Qualifying the lead and it converts into Opportunity.

    When the screen switch from Lead to Opportunity code doesn't work. I need to close the opportunity and open back & refresh the page then it works.

    Also tested with multiple browser, still same.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Code error for show/hide tab based on BPF

    My mistake , Updated the above code its should be "addOnStageChange" instead "addOnStageChanged"

  • Syed_Faisal Profile Picture
    815 on at
    RE: Code error for show/hide tab based on BPF

    Hi Gowtham,

    Code is working fine but in case-filter.pngbetween getting this pop up error.

  • Syed_Faisal Profile Picture
    815 on at
    RE: Code error for show/hide tab based on BPF

    Thanks Radu for the suggestion,

    I am not good in code so, was delay to understand the answer.

  • Syed_Faisal Profile Picture
    815 on at
    RE: Code error for show/hide tab based on BPF

    Thanks a lot Goutham,

    Code works absolutely fine. Thanks again,

  • Verified answer
    Radu Chiribelea Profile Picture
    6,667 on at
    RE: Code error for show/hide tab based on BPF

    When I said onChange I was referring to Xrm.Page.data.process.addOnStageChange(checkBPF);

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Code error for show/hide tab based on BPF

    Hi Sayed ,

    Try with this -

      //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);
    
            }
    
    
        }
  • Syed_Faisal Profile Picture
    815 on at
    RE: Code error for show/hide tab based on BPF

    I just tried on TabOnChange but still no luck

  • Syed_Faisal Profile Picture
    815 on at
    RE: Code error for show/hide tab based on BPF

    Hi Radu,

    There is no OnChange event option here, Code should work based on Next Stage action.

    When clicking on Next Stage, it should work.

  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at
    RE: Code error for show/hide tab based on BPF

    seems that onChange the event handler is not called.

    Can you add a debugger or a breakpoint within your code and see if gets hit?

    What values do you see for the locals?

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans