I am trying to create a link
dynamically using the below code:
'<span>'+
'<a href="/'+ row.id+'" target="_blank">'+ row.name+
'</a>'+
'</span>'
The created link works well in normal view. It redirects to the record detail page.
Now, the problem I am facing is, to open a subtab, when the link is being accessed from Console View.
I have gone through the openSubtab documentation. But didn't work for me.
This is the code by referring the documents:
function openSubTab(recId){
var redirectUrl = recId;
if (sforce.console.isInConsole()) {
sforce.console.getEnclosingTabId(function(enclosingResult){
sforce.console.getEnclosingPrimaryTabId(function(primaryResult){
sforce.console.openSubtab(primaryResult.id, redirectUrl, true, '', null);
});
});
} else {
window.top.location.href = '/'+redirectUrl
}
}
Link Generation Code(Added onClick):
'<span>'+
'<a href="#" onClick = "openSubTab('+row.Id+');return false"" class="easyui-linkbutton" target="_blank">'+ row.name+
'</a>'+
'</span>'
Is there a better way to do what I am trying to accomplish?
Note: The record ID would be dynamic.
onclick
is case sensitive and mixing JavaScript and HTML is quite error prone. Added an answer which I feel to be more elegant.