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
Albert Xie 7Albert Xie 7 

Service cloud chat findOrCreate on custom fields not populating in Contact

I am trying to configure Service Cloud chat with our website. To correlate the chat session with a user in our own internal system I would like to pass our own user ID to the contact object in Salesforce. 

Here's the code I have so far: 

liveagent.addCustomDetail("user id", 123);

liveagent.findOrCreate('Case')
    .saveToTranscript('CaseId')
    .showOnCreate();

liveagent.findOrCreate('Contact')
    .map('user id', 'user id, true, true, true)
    .saveToTranscript('ContactId')
    .linkToEntity('Case','ContactId')
    .showOnCreate();

 

 

I am certain the field "user id" exists in our salesforce object.

Any help would be much appreciated! 

Anil JAdhav 14Anil JAdhav 14
1. This code will be added to the page where you are adding chat button and deployment code.
<script type='text/javascript'>
var test = liveagent.addCustomDetail('test','Test Value');
</script>

2. Add the following code on the Pre-Chat Form Page.
<script type='text/javascript' src='https://c.la1c1.salesforceliveagent.com/content/g/js/32.0/prechat.js'></script>
<script type="text/javascript">
var detailCallback = function (details){
    for (var i = 0; i < details.customDetails.length; i++) {
        if(details.customDetails[i].label == 'test'){
            console.log(details.customDetails[i].value);
        }
    }
};
//First parameter is Chat URL. This is same as generated in Live Chat deployment code and can be used here
//This might be different for different users
//For example, in my Live chat deployment, the chat URL was 'https://d.la1c1.salesforceliveagent.com/chat' as defined in liveagent.init('https://d.la1c1.salesforceliveagent.com/chat', '5724000000000XX', '00De000000XXXXX');
liveagent.details.preChatInit('https://d.la1c1.salesforceliveagent.com/chat','detailCallback');

Let me know if this helps.