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
Zach Gavin DelacroixZach Gavin Delacroix 

addcustomDetail dynamic value liveagent

Hello,

Can anyone please give me idea how to dynamically get value from addCustomDetail in LiveAgent.

This code is not working..
liveagent.addCustomDetail("First_Name",document.getElementById("FirstName").value);

and here's the whole Code.
 
<script type='text/javascript' src='https://c.la1-c1cs-ukb.salesforceliveagent.com/content/g/js/41.0/deployment.js'></script>

<script type='text/javascript'>
 
//Custom Details
  liveagent.addCustomDetail("Customer_Name",document.getElementById("prechat_field_name").value);
  //CASE
  liveagent.addCustomDetail("Case_Status", "New");
  liveagent.addCustomDetail("Case_Origin", "Chat");
  liveagent.addCustomDetail("Case_Record Type", "01228000000isic");
  liveagent.addCustomDetail("Case_Product", "House and Land");
  liveagent.findOrCreate("Case")
    .map("Subject","Case_Origin",false,false,true)
    .map("Status","Case_Status",false,false,true)
  	.map("Product__c","Case_Product",false,false,true)
  	.map("RecordTypeId","Case_Record",false,false,true)
    .saveToTranscript("CaseId")
    .showOnCreate();
  
  
//End of Custom Details
liveagent.init('https://d.la1-c1cs-ukb.salesforceliveagent.com/chat', '5725D000000000f', '00D5D0000000TZM');
</script>
I hope you can help me here.. Thank you!


 
Matías Serrano VeraMatías Serrano Vera
Hi Zach. I see two possible reasons:
  1. The order of execution and the code that you are executing
  2. The Names that you're giving to the values (specifically, the underscore).
Maybe you should try something like this:
 
liveagent.init('https://d.la1-c1cs-ukb.salesforceliveagent.com/chat', '5725D000000000f', '00D5D0000000TZM');

//Custom Details
  liveagent.addCustomDetail("Customer_Name",document.getElementById("prechat_field_name").value);
  //CASE
  liveagent.addCustomDetail("Case_Status", "New");
  liveagent.addCustomDetail("Case_Origin", "Chat");
  liveagent.addCustomDetail("Case_Record Type", "01228000000isic");
  liveagent.addCustomDetail("Case_Product", "House and Land");
  liveagent.findOrCreate("Case").map("Subject","Case_Origin",false,false,true)
  liveagent.findOrCreate("Case").map("Status","Case_Status",false,false,true)
  liveagent.findOrCreate("Case").map("Product__c","ase_Product",false,false,true)
  liveagent.findOrCreate("Case").map("RecordTypeId","Case_Record",false,false,true)
  liveagent.findOrCreate("Case").saveToTranscript("CaseId")
  liveagent.findOrCreate("Case").showOnCreate();
  
  
//End of Custom Details

For the second poing: let me know if you want to give this values to standar fields or this are just the labels for the fields.