0

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.

  • Can you post your code? How are you accessing? Is that from console component? – Santanu Boral Feb 20 '17 at 20:16
  • you can edit your ques and put the code – Santanu Boral Feb 21 '17 at 20:06
1

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

There is a method called getPrimaryTabIds() available in Console Integration Toolkit. The method detail page says "Returns all of the IDs of open primary tabs. This method is only available in API version 26.0 or later."

This method is asynchronous so it returns its response in an object in a callback method. In this callback method, you can loop through the array of primary tab ids to check the if the tab id in question is a Primary Tab or SubTab.

You can write something like this:

function checkSubTab(tabId) {
    tabId = tabId;
    //Get the primary tab IDs
    sforce.console.getPrimaryTabIds(checkSubTabCallback);
}
var checkSubTabCallback = function(result) {
    var arrPriTabs = result.ids;
    if (result.error) {
        alert("Error message is " + result.error);
    } else {
        for (var i = 0; i < arrPriTabs.length; i++) {
            if (arrPriTabs[i] == tabId) {
                alert("Primary Tab");
                return false;
            }
        }
        alert("Sub Tab");
        return true;
    }
};
  • I get the idea there. But my issue is actually with the tabId itself. In your example you have checkSubTab(tabId) ... that tabId is always a SubTab Id even though I feel like it should be a primaryTabId. 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. – Patrick Feb 21 '17 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.