In Service console, if the Primary tab is already open, we need to focus the primary tab. How to check whether the primary tab is already opened in console or not?
1 Answer
I'd suggest using a combination of getPrimaryTabIds and getPageInfo methods from the toolkit in order to determine if a tab is open, based on whatever criteria you want. A sample of what this code might look like for finding a tab with a given object ID is below
<apex:page>
<script src="/support/console/37.0/integration.js" type="text/javascript"></script>
<script>
function findTab(criteria) {
sforce.console.getPrimaryTabIds(getPageInfo);
function getPageInfo(result) {
if(result.ids.length==0) {
alert('No Tabs Open');
return;
}
for(i=0; i<result.ids.length; i++) {
sforce.console.getPageInfo(result.ids[i], checkPresence);
}
}
function checkPresence(result) {
if(JSON.parse(result.pageInfo).objectId==criteria) {
alert('Tab Found');
}
}
}
</script>
<a href="#" onclick="findTab('001xx0000012345');">Find Tab</a>
</apex:page>