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
pumbaapumbaa 

Create Javascript in Service Cloud Console

Hi,

I have a great need in enabling Javascript in Service Cloud Console.

For example, I have a javascript in home page component which expand the range of the Calendar for date field. This works fine for Accounts and Contacts in regular Sales console when I enable the home page component in home page layout. However when it goes to SCC everything is in an iframe.

What I'm doing right now is in SCC Account page -> edit page layout -> click Custom Console Components

In Primary Tab Components -> Right Sidebar, I choose Type: Visualforce Page, Visualforce Page: HomePageLoader (this visualforce page is basically load the Home Page in an iframe of the VF page so javascript in Home Page component can make change to the main page. Note: this is a hack since VF page and standard SF page are using different domains)

This works most of the time but doesn't seem to be a good practise. It seems like sometimes run into a concurrency problem and javascripts (home page in the iframe) will never finish loading.

 

Here's the code for HomePageLoader VF page:

<apex:page >
<apex:includeScript value="/support/console/25.0/integration.js"/>
<script type="text/javascript">

(function () {
   setTimeout(function () {
       sforce.console.getEnclosingPrimaryTabId(function (result) {
           var subdomain = '{!URLFOR(JSENCODE($Action.Account.Tab), JSENCODE($ObjectType.Account), null, true)}';
           subdomain = subdomain.substring(0, subdomain.indexOf(".salesforce.com"));
               
           var homePageUrl = subdomain + ".salesforce.com/home/home.jsp?tabId=" + encodeURIComponent(result.id);
           setTimeout(function () { 
               var iframe = "<iframe src='" + homePageUrl + "'></iframe>";
               document.write(iframe);
           }, 50);
       });
   }); 
})();

</script>
</apex:page>
 
Here's the code for my Calendar expander Javascript&colon;
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(
function() {
var startYear = 1930;
var endYear = 2050;
var optionsString = '';
if (startYear < endYear) {
for (i = startYear; i < endYear + 1; i++) {
optionsString += "<option value=\""+i+"\">" + i
+ "</option>";
}
$('#calYearPicker').html(optionsString); //change calYearPicker in regular sales console

for (j = 0; j < window.top.frames.length; j++) {
                                               //travers thru the frames in SCC and change calYearPicker in SCC
$('#calYearPicker', window.top.frames[j].document)
.html(optionsString);
}

}
});
</script>


Any advise or workaround will be great.

Thanks in advance,
Ricky

kka_zzzsaikka_zzzsai

Very very creative..!