function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Srikanth Sunkara 23Srikanth Sunkara 23 

javascript Custom Code Button

Hi,

I am having this code under Custom button click ffor case record and it works fine in Sales Cloud but the same code is not working as expected in service console(redirection to Case owner change page doesnt happen)

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/support/console/29.0/integration.js")} 

var recId = window.location.href.substring(window.location.href.lastIndexOf('/') + 1); 
var c = new sforce.SObject("Case"); 
c.id = "{!Case.Id}"; 

// make the field change 
//c.Agent_Handover_From__c= '{!$User.Id}'; 
c.Agent_Handover_From__c= '{!$User.FirstName}'+ ' ' + '{!$User.LastName}'; 
//{!$User.FirstName} {!$User.LastName}"; 
c.Agent_Handover_Time__c = new Date(); 
c.Stage__c='Sales HandOver'; 
c.RecordTypeId ='01290000000iaw4'; 
// save the change 
sforce.connection.update([c]); 
var redirectURL = '/'+ recId + '/' + 'a?retURL=%2F' + recId ; 
//window.location = '/'+ recId + '/' + 'a?retURL=%2F' + 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.location.href = redirectURL; 
}

Can you please suggest the change in the code to make it work in service console.


Regards
Srikanth Sunkara
Eric AnEric An
var recId = window.location.href.substring(window.location.href.lastIndexOf('/') + 1); 

maybe need to replace to function 'getFocusedSubtabObjectId()' or 'getFocusedPrimaryTabId()', which one chose decide by the object show in the console. And also you can use all and check by method.
Srikanth Sunkara 23Srikanth Sunkara 23
Thanks! Eric. I will give a try and will let you know.
Srikanth Sunkara 23Srikanth Sunkara 23
Hi Eric,
i took a different approach to resolve the problem. I have implemented VF page with Extension controller to reditrect to a url and also update case  values.it worked.

Regards
Srikanth Sunkara