Reusable function to open a subtab in service console

The following function will help you to open a sub tab. Service console kit offers lot of methods with callback feature & using them we can achieve the UI requirements.

Here in this scenario goal is to open a sub tab considering the window is opened console or not and making it dynamic so that any page can access this resource file in the static resource.

/**Params
* 1. url ----- string URL
* 2. tabName - String tab name
**/
function openLink(url, tabName) {
var openSubtab = function openSubtab(result) {
//Now that we have the primary tab ID, we can open a new subtab in it
var primaryTabId = result.id;
sforce.console.openSubtab(primaryTabId, '/' + url, true, tabName, null, tabName);
};
if (sforce.console.isInConsole()) {
//First find the ID of the primary tab to put the new subtab in
sforce.console.getEnclosingPrimaryTabId(openSubtab);
} else {
(window.open('/' + url, '_blank')).focus();
}
}
More information can be seen @ https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_opensubtab.htm

Comments