Find your content:

Search form

You are here

Issue with passing parameters in Service Cloud Console Integration Toolkit

 
Share

i am currently having certain hyperlinks in VF page which i need to make compatible in service cloud and hence using the API toolkit.I am quite new to callback methods, what is the syntax to pass arguments into the callback method.Any help will be very useful, below is the current code i am using which is working fine but its doesn't take any arguments. Is there a way i can use like openReportedContact('{!caserec.id'}) and use this parameter in the callback function callBackopenReportedContact(result,'{!caserec.id'}) as well. The purpose is to write a generic JS method, curretnly i have 3 JS method doing the same work and want to write one generic JS.

VF Page
<A HREF="#" onClick="openReportedContact();return false">{!caserec.contact.name}</A>

function openReportedContact() {
     if(!sforce.console.isInConsole())
         window.parent.location.replace('/{!case.ContactId}');
     else sforce.console.getEnclosingPrimaryTabId(callBackopenReportedContact);
}

function callBackopenReportedContact(result) {
 sforce.console.openSubtab(result.id, '/{!case.ContactId}',true,'{!case.contact.name}', null);
};

Attribution to: Anil Shivaraj

Possible Suggestion/Solution #1

A better way to do this is with a closure. The code is very similar to your example, but we can lose the global variables if we change the callBackopenTab function to be an anonymous function defined inline. It then has access to the local variables in the enclosing scope:

<A HREF="#" onClick="openTab('{!caserec.contactid}','{!caserec.contact.name}');return false">{!caserec.contact.name}</A>  

function openTab(recid, recname) {
  if(!sforce.console.isInConsole())
    window.parent.location.replace('/'+recid);
  else
    sforce.console.getEnclosingPrimaryTabId(function(result) {
      sforce.console.openSubtab(result.id, '/'+recid , true, recname, null);
    });
}

If you really wanted to keep the callBackopenTab function, you could alternatively do:

<A HREF="#" onClick="openTab('{!caserec.contactid}','{!caserec.contact.name}');return false">{!caserec.contact.name}</A>  

function openTab(recid, recname) {
  if(!sforce.console.isInConsole())
    window.parent.location.replace('/'+recid);
  else
    sforce.console.getEnclosingPrimaryTabId(function(result) {
      callBackopenTab(result, recid, recname);
    });
}

function callBackopenTab(result, recordid, recordname) {
  sforce.console.openSubtab(result.id, '/'+recordid , true, recordname, null);
}; 

Note - I don't have a test rig for this, but it should work for you!


Attribution to: metadaddy

Possible Suggestion/Solution #2

I did it finally using a global variable in JS. Not sure if its the best solution, but wanted to share with you guys and let me know if there is a better way. Now this becomes generic method for any record where i just pass in the recordid and name which reduces redundant code.

VF page

<A HREF="#" onClick="openTab('{!caserec.contactid}','{!caserec.contact.name}');return false">{!caserec.contact.name}</A>  

//globale JS variables
var recordid;
var recordname;

function openTab(recid, recname) {
     recordid = recid;
     recordname = recname;
  if(!sforce.console.isInConsole())
     window.parent.location.replace('/'+recid);
  else
     sforce.console.getEnclosingPrimaryTabId(callBackopenTab);
  }
function callBackopenTab(result) {
     sforce.console.openSubtab(result.id, '/'+recordid , true,recordname,null);
 }; 

Attribution to: Anil Shivaraj
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/5037

My Block Status

My Block Content