Loading

Pass value from the prechat form to a custom field on the LiveChatTranscript object when using lightningsnapin:prechatAPI

Data pubblicazione: Oct 13, 2022
Descrizione
In general, Snap-ins does not load Chat apis on the page. When we send a chat request, we send the prechat form details to find or create to create entities on the Salesforce side. The lightningsnapin:prechatAPI does not support passing these information. Also, locker service will prevent us from accessing the global window object (where embedded_svc.settings.extraPrechatFormDetails exists).
 
Risoluzione
If you want to save dynamic values from the pre-chat form directly into a custom field in the transcript object.
  • Create a custom field on the transcript object (for example, PrechatText__c).
  • Pass the transcript fields in the extra pre-chat form details without passing the value property. 
embedded_svc.settings.extraPrechatFormDetails = [{"label":"Text", "transcriptFields": ["PrechatText__c"]}];

Note:  This setting will live in the container page where the Snap-in is hosted, not within the custom prechat component.
  • To capture a value from the prechat component and update embedded_svc.settings.extraPrechatFormDetails before the chat request is sent, we need to use a custom event to let the container page know what should be the value of custom LiveChatTranscript field.
  • In the custom prechat component's start chat function, fire a CustomEvent that includes the startChat function. (Sample Code below)
 
if(cmp.find("prechatAPI").validateFields(fields).valid) {
    var event = new CustomEvent(
        "setCustomField",
        {
            detail: {
                callback: cmp.find("prechatAPI").startChat.bind(this, fields),
                customField: "value"
            }
        }
    );
    // Dispatch the event.
    document.dispatchEvent(event);
} else {
    console.warn("Prechat fields did not pass validation!");
}

In your container page, add a listener for the CustomEvent. The handler will update extraPrechatFormDetails and then call the startChat function.
 
document.addEventListener(
	"setCustomField",
	function(event) {
		embedded_svc.settings.extraPrechatFormDetails[0].value = event.detail.customField;
		// Fire startChat callback.
		event.detail.callback();
	},
	false
);

 
Numero articolo Knowledge

000380580

 
Caricamento
Salesforce Help | Article