Embedded Service Chat component in community - using "Snippet Settings File" javascript to override pre-chat file is not working
Eventually I did succeed on the task to use this javascript override.
But I did it in a specific way - not as in my question
In this snippet I am disabling the creation of case and contact, and in a trigger on the chat transcript
object I am creating them, with custom fields saved on the chat transcript
object.
JavaScript snippet:
window._snapinsSnippetSettingsFile = (function() {
// Logs that the snippet settings file was loaded successfully
console.log("Snippet settings file loaded.");
// set all fields entered in the pre-chat widown into custom fields on the chat transcript object
// fields without a value entered here - will get the value from the form itself
embedded_svc.snippetSettingsFile.extraPrechatFormDetails = [
{
"label": "First Name",
"transcriptFields": ["Form_First_Name__c"],
"displayToAgent":true
},
{
"label": "Last Name",
"transcriptFields": ["Form_Last_Name__c"],
"displayToAgent":true
},
{
"label": "Email",
"transcriptFields": ["Form_Email__c"]
},
{
"label": "Subject",
"transcriptFields": ["Form_Subject__c"],
"displayToAgent":true
},
{
"label": "Product",
"value": "myProduct",
"transcriptFields": ["Form_Product__c"],
"displayToAgent":true
},
{
"label": "Origin",
"value": "Chat",
"transcriptFields": ["Form_Origin__c"]
}
];
// disable creation of a contact and a case:
// this will be handled by the chat transcript trigger that will create a case that will create a contact
embedded_svc.snippetSettingsFile.extraPrechatInfo = [{
"entityName":"Contact",
"entityFieldMaps": [{
"doCreate":false,
"doFind":false,
"fieldName":"LastName",
"isExactMatch":false,
"label":"Last Name"
},
{
"doCreate":false,
"doFind":false,
"fieldName":"FirstName",
"isExactMatch":false,
"label":"First Name"
},
{
"doCreate":false,
"doFind":false,
"fieldName":"Email",
"isExactMatch":false,
"label":"Email"
}]
},
{
"entityName":"Case",
"entityFieldMaps": [{
"doCreate":false,
"doFind":false,
"fieldName":"Subject",
"isExactMatch":false,
"label":"Subject"
}]
}];
})();
Trigger - create case:
trigger ChatTranscript_Trigger on LiveChatTranscript (after delete, after insert, after undelete, after update, before delete, before insert, before update) {
if (Trigger.isBefore && Trigger.isInsert) { // Before Insert
System.debug('\n\n\n\nChatTranscript_Trigger before insert\n\n\n\n');
for (LiveChatTranscript newChat: Trigger.new) {
// all entered fields in the pre-chat form should be copied here to the case
Case newCase = new Case();
newCase.SuppliedName = newChat.Form_First_Name__c;
newCase.Web_LastName__c = newChat.Form_Last_Name__c;
newCase.SuppliedEmail = newChat.Form_Email__c;
newCase.Subject = newChat.Form_Subject__c;
newCase.Product__c = newChat.Form_Product__c;
newCase.Origin = newChat.Form_Origin__c;
newCases.add(newCase);
}
insert newCases;
}
else if (Trigger.isBefore && Trigger.isUpdate) { // Before Update
}
else if(Trigger.isBefore && Trigger.isDelete) { // Before Delete
}
else if (Trigger.isAfter && Trigger.isUnDelete) { // After UnDelete
}
else if (Trigger.isAfter && Trigger.isUpdate) { // After Update
}
else if (Trigger.isAfter && Trigger.isDelete) { // After Delete
}
else if (Trigger.isAfter && Trigger.isInsert) { // After Insert
}
}