Loading

Use JavaScript buttons with the Console Integration Toolkit

Veröffentlichungsdatum: Jun 26, 2023
Beschreibung

The examples in the Console Integration Toolkit Developer Guide all use Visual Force pages. The VF pages are Smart HTML. They can detect when a method that is being called is located in the page.  But Javascript button scripts act like regular HTML. When using Javascript to script buttons, it's necessary to load any scripts or declarations first and any methods that will require scripts later.

Note: Javascript buttons are not supported in Lightning as of now, and so this resolution applies only to Classic. 
Lösung

Salesforce Console Integration Toolkit allows developers to customize the Console and integrate 3rd party systems with the console. The development guide shows several examples that are very useful. These examples use a Visual Force page, which employs Smart HTML. This means that the load order of scripts and components won’t matter. Smart HTML takes this into consideration, and can locate scripts that may be loaded later that are needed by a CTI method.   

In use cases where a button is used to implement a CIT method, javascript is often used to script the button. In these cases, regular HTML means that the order of load must be considered. Look at these two examples:   

CTI Developer Guide Example using Visual Force Page:

<apex:page standardController="Case">

// Note that method is called before script is loaded-  Works fine in Visual Force page! 
     <A HREF="#" onClick="testOpenPrimaryTab();return false"> 
         Click here to open a new primary tab</A> 

    <apex:includeScript value="/support/console/38.0/integration.js"/>
    	<script type="text/javascript">
        		function testOpenPrimaryTab() {
            	//Open a new primary tab with the salesforce.com home page in it
            	sforce.console.openPrimaryTab(null, 'http://www.salesforce.com', false, 
                	'salesforce', openSuccess, 'salesforceTab');
        	}
        
        	var openSuccess = function openSuccess(result) {
            	//Report whether opening the new tab was successful
            	if (result.success == true) {
                		alert('Primary tab successfully opened');
            	} else {
                		alert('Primary tab cannot be opened');
            	}
        		};     
  	</script>
</apex:page>
 

Example for Javascript, like you might use for button script:

{!REQUIRESCRIPT("/support/console/38.0/integration.js")}

   var openSuccess = function openSuccess(result) {
   //Report whether opening the new tab was successful
   if (result.success == true) {
      alert('Primary tab successfully opened');
   } else {
      alert('Primary tab cannot be opened');
   }
   };

// Notice here that method is called AFTER script is loaded.  Javascript needs this!  

   sforce.console.openPrimaryTab(null, 'http://www.salesforce.com', false, 'salesforce',    openSuccess, 'salesforceTab');
 Summary:  When using CTI Developer Guide examples outside of a Visual Force page, be sure to consider the order of loading so that scripts are loaded before methods that need those scripts are called.   
Nummer des Knowledge-Artikels

000383520

 
Laden
Salesforce Help | Article