Embedded Service - Passing in non-standard pre chat details
Overriding default Embedded Service pre chat behavior:
By default, when the chasitor fills in the prechat, Embedded Service takes care of invoking the prechat APIs from Live agent and doing the findorcreate of entities but there are certain cases when there’s a need to override the default behavior. This can be done by adding embedded_svc.settings.extraPrechatInfo and embedded_svc.settings.extraPrechatFormDetails to the code snippet.
There are two types of pre-chat information that get passed from the widget to LiveAgent: info (prechatInfo), and form details (prechatFormDetails).
Form details (prechatFormDetails) describe an individual field, such as “Email”. They have a label (“Email”), a value, an array of transcriptFields (API names of transcript object fields that will inherit the prechat field’s value), and a displayToAgent boolean (if the field is available in the little popup when you hover over a pending chat).
Info (prechatInfo) allows mapping from fields to entities. It has an entityName (“Lead”), a showOnCreate boolean (should the created object be shown to the agent?), a saveToTranscript string (what’s the label we should give for the transcript row that displays the newly created object), and an array of entity-field mappings. The ‘entityFieldMap’ has the following in it :
More details of Prechat API and the fields can be found here.
There are two sources of prechat info and prechat form details: setup values (“regular” prechatInfo and prechatFormDetails), and extra values provided in the snippet by the user (“extra” prechatInfo and prechatFormDetails). These values are merged into one array, with extra values taking precedence over regular values, and then sent to FindOrCreateCommand.
IMPORTANT: If you have the same fields in prechat and extra prechat, the merge happens based on the label name. So if you want to override default settings for fields defined in the setup you need to make sure the label names match in the extraPrechatInfo
Examples:
1. Overriding fields from Setup: To test this, select a service scenario in setup and to that snippet add the below. This would cause a merge and the extraPrechatInfo and extraPrechatFormDetails would override the first name, last name and subject passed in from the chasitor.
embedded_svc.settings.extraPrechatFormDetails = [{"label":"First Name","value":"Marc","transcriptFields":[],"displayToAgent":true},{"label":"Last Name","value":"Benioff","transcriptFields":[],"displayToAgent":false},{"label":"Email","value":"benioff@salesforce.com","transcriptFields":[],"displayToAgent":true},{"label":"issue","value":"Sales forecasts","transcriptFields":[],"displayToAgent":true}] ;
embedded_svc.settings.extraPrechatInfo =
[{"entityName":"Contact","showOnCreate":true,"linkToEntityName":"Case","linkToEntityField":"ContactId","saveToTranscript":"Contact","entityFieldMaps":[{"isExactMatch":true,"fieldName":"FirstName","doCreate":true,"doFind":true,"label":"First Name"},{"isExactMatch":true,"fieldName":"LastName","doCreate":true,"doFind":true,"label":"Last Name"},{"isExactMatch":true,"fieldName":"Email","doCreate":true,"doFind":true,"label":"Email"}]},{"entityName":"Case","showOnCreate":true, "saveToTranscript":"Case", "entityFieldMaps":[{"isExactMatch":false,"fieldName":"Subject","doCreate":true,"doFind":false,"label":"issue"},{"isExactMatch":false,"fieldName":"Status","doCreate":true,"doFind":false,"label":"Status"},{"isExactMatch":false,"fieldName":"Origin","doCreate":true,"doFind":false,"label":"Origin"}]}]
2. Add extraPrechatInfo with a new entity Account: In case your business needs an entity which is not available in the standard scenarios that Embedded Service for Web exposes e.g. you need to be able to create an account when a chat comes in you can do that by defining that entity in the extraPrechatInfo
embedded_svc.settings.extraPrechatInfo = [{"entityName":"Contact","showOnCreate":true,"linkToEntityName":"Case","linkToEntityField":"ContactId","saveToTranscript":"Contact","entityFieldMaps":[{"isExactMatch":true,"fieldName":"FirstName","doCreate":true,"doFind":true,"label":"firstName"},{"isExactMatch":true,"fieldName":"LastName","doCreate":true,"doFind":true,"label":"LastName"},{"isExactMatch":true,"fieldName":"Email","doCreate":true,"doFind":true,"label":"Email"}]},{"entityName":"Case","showOnCreate":true,"entityFieldMaps":[{"isExactMatch":false,"fieldName":"Subject","doCreate":true,"doFind":false,"label":"issue"},{"isExactMatch":false,"fieldName":"Status","doCreate":true,"doFind":false,"label":"Status"},{"isExactMatch":false,"fieldName":"Origin","doCreate":true,"doFind":false,"label":"Origin"}]},
{"entityName":"Account","showOnCreate":true,"entityFieldMaps":[{"isExactMatch":true,"fieldName":"Name","doCreate":true,"doFind":true,"label":"LastName"}]}];
embedded_svc.settings.extraPrechatFormDetails = [{"label":"firstName","value":"Usain","transcriptFields":[],"displayToAgent":true},{"label":"LastName","value":"Bolt","transcriptFields":[],"displayToAgent":false},{"label":"Email","value":"bolt@gmail.com","transcriptFields":[],"displayToAgent":true},{"label":"issue","value":"Laptop broken","transcriptFields":[],"displayToAgent":true}] ;
3. Disable creating Contacts on each chat: If you want to just find and not create a contact on each incoming chat you can disable contact creation by just adding this extraPrechatInfo.
embedded_svc.settings.extraPrechatInfo = [{"entityFieldMaps":[{"doCreate":false,"doFind":true,"fieldName":"LastName","isExactMatch":true,"label":"Last Name"},{"doCreate":false,"doFind":true,"fieldName":"FirstName","isExactMatch":true,"label":"First Name"}, {"doCreate":false,"doFind":true,"fieldName":"Email","isExactMatch":true,"label":"Email"}],"entityName":"Contact","saveToTranscript":"Contact","showOnCreate":true}];000383795

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.