[SalesForce] In Service Console Apps – how can I tell if I’m on a subtab or primary tab

The value returned from sforce.console.getEnclosingTabId seems to always be a subtab value. Even though it is not opened as a SubTab.

I've tried to compare against the sforce.console.getEnclosingPrimaryTabId and other functions but it doesn't look right.

Is there something that I'm missing?

This is what I was trying to do.

sforce.console.getEnclosingTabId( function (enclosingTabInfo) { 
   var enclosingTabId = enclosingTabInfo.id;

   sforce.console.getEnclosingPrimaryTabId( function (primaryTabInfo) {
     if (enclosingTabId === primaryTabInfo.id) { 
       console.log("Is primary Tab"); 
     } else { console.log("Is SubTab");
   });
 })

I think I know what is happening. All Tabs have a subtab (by default even if it doesn't look like it). So if you have one primary Tab and you do a getSubtabIds() call, it will return a single subtab id still. And that is what is being returned by the getEnclosingTabId() call. So I guess to check if it is a subtab I'll have to check if the primary Tab has two subtabs or not.

Best Answer

I realize this is 2 years late, but in hopes this could help someone else, here's how to determine whether you are in a subtab or primary tab.

function isPgOpenInSubtab(primaryTabId, enclosingTabId){
    if(primaryTabId && enclosingTabId)
        return !(enclosingTabId === primaryTabId);

    return false;
}

Example use:

sforce.console.getEnclosingPrimaryTabId(function(pTabResult){
    sforce.console.getEnclosingTabId(function(eTabResult){
        const pTabId = pTabResult.id;
        const eTabId = (eTabResult.success ? eTabResult.id : null);
        const isSelfOpenInSubtab = isPgOpenInSubtab(pTabId, eTabId);
    });
});
Related Topic