Find and Create Records Deployment API Code Sample

Test and preview how automatically creating records can work with your Chat deployments using this code sample.

The following code searches for and creates records when an agent begins a chat with a customer using the following methods:

  • addCustomDetail
  • findOrCreate
  • findOrCreate.map
  • findOrCreate.saveToTranscript
  • findOrCreate.linkToEntity
  • findOrCreate.showOnCreate
1<script type='text/javascript'>
2/* Creates a custom detail called First Name and sets the value to "Jane" */
3liveagent.addCustomDetail("First Name", "Jane");
4
5/* Creates a custom detail called Last Name and sets the value to "Doe" */
6liveagent.addCustomDetail("Last Name", "Doe");
7
8/* Creates a custom detail called Phone Number and sets the value to "555-1212" */
9liveagent.addCustomDetail("Phone Number", "415-555-1212");
10
11/* Creates a custom detail called Case Subject and sets the value to "Best snowboard for
12a beginner" and will perform a knowledge search when the chat is accepted for the agent */
13
14liveagent.addCustomDetail("Case Subject", "Best snowboard for a beginner").doKnowledgeSearch();
15
16/* Creates a custom detail called Case Status and sets the value to "New" */
17liveagent.addCustomDetail("Case Status", "New");
18
19/* This does a non-exact search on cases by the value of the "Case Subject" custom detail.
20	If no results are found, it will create a case and set the case's subject and status
21	The case that's found or created will be associated to the chat and the case will open in
22	the Console for the agent when the chat is accepted */
23liveagent.findOrCreate("Case").map("Subject","Case Subject",true,false,true).map("Status","Case Status",false,false,true).saveToTranscript("CaseId").showOnCreate();
24
25/* This searches for a contact whose first and last name exactly match the values in the custom details for First and Last Name
26	If no results are found, it will create a new contact and set it's first name, last name, and phone number to the values in the custom details */
27liveagent.findOrCreate("Contact").map("FirstName","First Name",true,true,true).map("LastName","Last Name",true,true,true).map("Phone","Phone Number",false,false,true);
28
29/* The contact that's found or created will be saved or associated to the chat transcript.
30The contact will be opened for the agent in the Console and the case is linked to the contact record */
31liveagent.findOrCreate("Contact").saveToTranscript("ContactId").showOnCreate().linkToEntity("Case","ContactId");
32</script>