1

We have a pre-chat form where the button is going to sit on a website that isn't hosted on Salesforce Sites or a Community. We have data about the logged in user that we'd like to pass into some fields on the pre-chat form. Examples being name and company.

Is there a way to pass this data into a pre-chat form?

Thanks

2
  • I don't think you can pass data to the pre-chat form. Do you want to display that information on the pre-chat form or do you need that information on the SF instance when the chat session is established. You can use javascript and methods like liveagent.addCustomDetail(..) before the liveagent.init(..) method in your web page. That information will not be visible on the pre-chat form but will be transferred to the SF instance when the chat session is started. A bit more information on what exactly you are trying to achieve would be helpful.
    – Aayush K
    Commented Dec 19, 2014 at 16:13
  • I am trying to pass the information through to Salesforce so that I can lookup the Account based on an external ID that exists within the webpage where the button code will be hosted. So basically the website passes through the ID and then it looks up against that ID in Salesforce for when it creates a Case to associate to that Account Commented Dec 19, 2014 at 19:18

2 Answers 2

0

You can use the Deployment API to pass the account parameters using javascript on the webpage. You need to add the following 2 lines before the liveagent.init(..) method.

liveagent.addCustomDetail('Account_Name', 'GenePoint'); liveagent.findOrCreate('Account').map('Name','Account_Name',true,true,false);

You can add more fields to perform search. A more complete example from documentation can be found at the following link.

Creating Records Deployment API Code Sample

Full code from the sample VF page that I created to test this.
As soon as the chat is initialized, the system searches for an Account called GenePoint and displays the detail page automatically.

<apex:page>

  <a id="liveagent_button_online_573i0000000NZnE" href="javascript://Chat" style="display: none;" onclick="liveagent.startChat('573i0000000NZnE')">ONLINE</a><div id="liveagent_button_offline_573i0000000NZnE" style="display: none;">OFFLINE</div><script type="text/javascript">
if (!window._laq) { window._laq = []; }
window._laq.push(function(){liveagent.showWhenOnline('573i0000000NZnE', document.getElementById('liveagent_button_online_573i0000000NZnE'));
liveagent.showWhenOffline('573i0000000NZnE', document.getElementById('liveagent_button_offline_573i0000000NZnE'));
});</script>

<script type='text/javascript' src='https://c.la2c1.salesforceliveagent.com/content/g/js/32.0/deployment.js'></script>
<script type='text/javascript'>

liveagent.addCustomDetail('Account_Name', 'GenePoint');
liveagent.findOrCreate('Account').map('Name','Account_Name',true,true,false);

liveagent.init('https://d.la2c1.salesforceliveagent.com/chat', '572i0000000NXE8', '00Di0000000jydC');

</script>

</apex:page>
1
  • This didn't seem to work for me :( Commented Apr 12, 2017 at 14:44
3

You can definitely pass custom data from Live Agent into the pre-chat form.

You can use the Live Agent deployment method .addCustomDetail to add details in the web page where your live chat button appears. NOTE: This web page where the chat is initiated can be hosted anywhere, does not need to be a Salesforce page.

Then, in your pre-chat form, there is a javascript library you can include which has a javascript API you can use to retrieve any of those custom details you've passed in from the initiating page. The method is called prechat.init() and is documented here:

https://developer.salesforce.com/docs/atlas.en-us.live_agent_dev.meta/live_agent_dev/live_agent_accessing_details_prechat_API_preChatInit.htm

NOTE: To use this method, you'll need to include the prechat JS library in your pre-chat form. For some reason, I can't find the documentation for this, but, here is the general format:

<script type='text/javascript' src='[[YOUR SERVER]]/content/g/js/29.0/prechat.js'>

...where the [[YOUR SERVER]] hostname can be found in your deployment setup page. There is an example with the ‘deployment.js’. Replace ‘deployment.js’ with ‘prechat.js' to get the URL.

1
  • THis is the correct answer, but doesn't seem to work for me Commented Apr 12, 2017 at 14:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .