I've just used openSubtab() successfully in a custom button to load a record in a new subtab in the Service Console, using the result[0].id returned from sforce.connection.create([record]).
I've also built some Custom Console Components as well that display lists of records in an apex:pageBlockTable that I would like to have the same functionality as a related list, to navigate to the individual records in their own subtabs, to save the user a click.
<apex:column width="50px" id="caseLink" headerValue="{!$ObjectType.case.fields.casenumber.label}" >
<apex:outputLink value="/{!historyItem.Id}" onclick="myOpenSubtab({!historyItem.id})" >{!historyItem.caseNumber}</apex:outputLink>
</apex:column>
If I wrap sforce.console.openSubtab() in a function myOpenSubtab(Id listItemId) that takes that {!historyItem.id} as a parameter, calling that function from the OnClick event of the link should do the trick, no?
I'm opening Cases in particular, so I created a Case-specific function for the purpose:
<script type="text/javascript">
function openCaseSubtab(id caseId) {
var openCase = sforce.console.getEnclosingPrimaryTabId(function(response) {
var primaryTabId = response.id;
// create a Case detail url (with a default value of 500 (Case prefix))
var url = "{!URLFOR($Action.Case.View, '500')}";
// replace the Id with the Case.Id passed in to the function
url = url.replace("500", caseId);
/* Define other parameters for openSubtab() */
var isActive = true;
var tabLabel = null;
var subtabId = null;
// Call the standard openSubtab method with the current Case's info
var newCaseTab = sforce.console.openSubtab(
primaryTabId, url, isActive, tabLabel, subTabId);
});
}
</script>
I'm getting the following errors:
Uncaught SyntaxError: Unexpected token ILLEGAL
Uncaught ReferenceError: srcUp is not defined
Anyone see anything obvious as far as how my function is implemented? In the custom button, everything is contained within this
sforce.console.getEnclosingPrimaryTabId(function(response) {
...
}
and a new function per se is not required. The openCase and newCaseTab variables were not necessary in the button implementation either; I added them here to prevent Compilation errors that prevented the page from saving.