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
ArunaAruna 

Custom list button in console from different objects. Important

I am having a custom button on case as related list button .
This button is on different objects like Account,opportunity,Quote and some othe custom objects.
The button works fine in out side the service cloud console , but it is nor working in console.
below code is for out side the console . I need a help how can put  this button for console.
This button also should  work in console , can any one please guide  me how to do this .

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}

//Get parent ID
var x = top.window.location.pathname;
var x1 = x.substring(1,x.length);
var xpre = x1.substring(0,3);

//Parent page is Account
if (xpre == '{!$ObjectType.Account}'){
var Acc = sforce.connection.query("Select Id, Name From Account Where Id = '" + x1 + "' limit 1");
var accrecords = Acc.getArray("records"); 
if (accrecords.length > 0){
top.window.location.href = '/setup/ui/recordtypeselect.jsp?ent=Case&nooverride=1&save_new_url=/500/e?nooverride=1&def_account_id=' + accrecords[0].Id + '&retURL=%2F' + x1;
}
}
//Parent page is Opportunity
else if (xpre == '{!$ObjectType.Opportunity}'){
var Opp = sforce.connection.query("Select Id, AccountId, Account.Name, Name From Opportunity Where Id = '" + x1 + "' limit 1");
var opprecords = Opp.getArray("records"); 
if (opprecords.length > 0){
top.window.location.href = '/setup/ui/recordtypeselect.jsp?ent=Case&nooverride=1&save_new_url=/500/e?nooverride=1&def_account_id=' + opprecords[0].AccountId + '&{!$Setup.OrgIDs__c.SR_OPRTY__c}_lkid='+ opprecords[0].Id + '&{!$Setup.OrgIDs__c.SR_OPRTY__c}='+ opprecords[0].Name + '&retURL=%2F' + x1;
}
}
//Parent page is Quotes
else if (xpre == '{!$ObjectType.UNUM_QUOTE__c}'){
var Qte= sforce.connection.query("Select Id, Name, OPRTY_ID__r.AccountId, OPRTY_ID__r.Name, OPRTY_ID__c From UNUM_QUOTE__c Where Id = '" + x1 + "' limit 1");
var Qterecords = Qte.getArray("records"); 
if (Qterecords.length > 0){
top.window.location.href = '/setup/ui/recordtypeselect.jsp?ent=Case&nooverride=1&save_new_url=/500/e?nooverride=1&def_account_id='+Qterecords[0].OPRTY_ID__r.AccountId+'&{!$Setup.OrgIDs__c.SR_OPRTY__c}_lkid='+ Qterecords[0].OPRTY_ID__c+'&{!$Setup.OrgIDs__c.SR_OPRTY__c}='+ Qterecords[0].OPRTY_ID__r.Name + '&{!$Setup.OrgIDs__c.SR_Quotes__c}_lkid='+ Qterecords[0].Id+'&{!$Setup.OrgIDs__c.SR_Quotes__c}='+ Qterecords[0].Name + '&retURL=%2F' + x1;
}
}

//Parent page is Enrollment Event
else if (xpre == '{!$ObjectType.Enrol_Event__c}'){
var Enr = sforce.connection.query("SELECT Id, Name, OPRTY_ID__c, OPRTY_ID__r.Name, OPRTY_ID__r.AccountId FROM Enrol_Event__c Where Id = '" + x1 + "' limit 1");
var enrrecords = Enr.getArray("records"); 
if (enrrecords.length > 0){
top.window.location.href = '/setup/ui/recordtypeselect.jsp?ent=Case&nooverride=1&save_new_url=/500/e?nooverride=1&def_account_id=' + enrrecords[0].OPRTY_ID__r.AccountId + '&{!$Setup.OrgIDs__c.SR_OPRTY__c}_lkid='+ enrrecords[0].OPRTY_ID__c + '&{!$Setup.OrgIDs__c.SR_OPRTY__c}='+ enrrecords[0].OPRTY_ID__r.Name + '&{!$Setup.OrgIDs__c.SR_ENROL_EVENT_ID__c}_lkid=' + enrrecords[0].Id + '&{!$Setup.OrgIDs__c.SR_ENROL_EVENT_ID__c}=' + enrrecords[0].Name + '&retURL=%2F' + x1;
}
}
//Suresh Added 
//Parent page is Rating Product 
else if (xpre == '{!$ObjectType.UW_Rating_Products__c}'){ 

var Enr = sforce.connection.query("SELECT Id ,Name,OPPTY_ID__c,    OPPTY_ID__r.Name, OPPTY_ID__r.AccountId, UNUM_QUOTE_ID__c, UNUM_QUOTE_ID__r.Name, PRODT_ID__r.Name, PRODT_ID__c FROM UW_Rating_Products__c Where Id = '" + x1 + "' limit 1"); 

var enrrecords = Enr.getArray("records"); 

if (enrrecords.length > 0){ 

top.window.location.href = '/setup/ui/recordtypeselect.jsp?ent=Case&nooverride=1&save_new_url=/500/e?nooverride=1&def_account_id=' + enrrecords[0].OPPTY_ID__r.AccountId + '&{!$Setup.OrgIDs__c.SR_OPRTY__c}_lkid='+ enrrecords[0].OPPTY_ID__c + '&{!$Setup.OrgIDs__c.SR_OPRTY__c}='+ enrrecords[0].OPPTY_ID__r.Name +'&{!$Setup.OrgIDs__c.SR_Quotes__c}_lkid='+ enrrecords[0].UNUM_QUOTE_ID__c + '&{!$Setup.OrgIDs__c.SR_Quotes__c}='+ enrrecords[0].UNUM_QUOTE_ID__r.Name +'&{!$Setup.OrgIDs__c.SR_Rating_Product_ID__c}_lkid='+ enrrecords[0].Id + '&{!$Setup.OrgIDs__c.SR_Rating_Product_ID__c}='+ enrrecords[0].Name + '&{!$Setup.OrgIDs__c.SR_Rating_Product_Name__c}='+enrrecords[0].PRODT_ID__r.Name+'&retURL=%2F' + x1; 
PrakashbPrakashb
Hi Aruna,

For the button to work in a console you need to have a look at the service cloud console integration toolkit.

First you need to identify whether the user is in console or not using the option sforce.console.isInConsole().

Then based on the result you either can use the standard option as you have used in your code or use the opensubtab or openprimarytab option from the toolkit. Please refer the link below for the complete toolkit.

http://www.salesforce.com/us/developer/docs/api_console/

A simpler solution is provided below.

https://success.salesforce.com/ideaView?id=08730000000YKxYAAW

Regards,
Prakash B