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
Eivind Pilskog 13Eivind Pilskog 13 

Live Agent Relationship Query through PreChat api

Hi,

I am trying to set up Live Agent with a prechat-form. In this prechat form I have three fields: Name, Phone and Email.
In my org, I have an Asset object that stores phonenumber and accountId.

Via the code below, I want to query in Asset for the corresponding accountId that matches the customers phone value he/she inserted in the form. I would then be able to map the created case (at the bottom of code) with the correct Account. I also want to pop this account in the service console for the agent.

I do not have any other way to identify the account based on the customers input. The case scenario is that the customer is a end user, that only will relate to his own phone number tied to the account. (often doesnot not the customer no or similar).

Is this possible, to do a "relationship query" via the Asset object to identify the correct Account? Any other way I can work this out in the background?

Thanks for any help or suggestions!
-Eivind
<apex:page showHeader="false"> 
<!-- This script takes the endpoint URL parameter passed from the deployment 
  page and makes it the action for the form -->
<script type="text/javascript">
(function() { 
  function handlePageLoad() {
    var endpointMatcher = new RegExp("[\\?\\&]endpoint=([^&#]*)");
    document.getElementById('prechatForm').setAttribute('action',
    decodeURIComponent(endpointMatcher.exec(document.location.search)[1]));
  } 
  if (window.addEventListener) {
    window.addEventListener('load', handlePageLoad, false);
  } else { 
    window.attachEvent('onload', handlePageLoad, false);
  }
})(); 
</script>
<h1>Pre-chat Form</h1> 
<form method='post' id='prechatForm'> 
      Full name: <input type='text' name='liveagent.prechat:FullNameDetail'
        id='customField1' /><br />
      Phone: <input type='text' name='liveagent.prechat:PhoneDetail'
        id='customField2' /><br />   
      Email: <input type='email' name='liveagent.prechat:EmailDetail'
        id='customField3' /><br />            

    <!-- Map the detail inputs to the Asset fields --> 
    <input type="hidden" name="liveagent.prechat.findorcreate.map:Asset" value="Telephone_Number__c,PhoneDetail;" />
    

      <!-- Specify to query for a matching Asset record using Telephonenumber field based on
        the value of Phone-->
      <input type="hidden" name="liveagent.prechat.findorcreate.map.doFind:Asset"
        value="Telephone_Number__c,true" />

      <!-- Return results only if there is an exact match of Email-->
      <input type="hidden" name="liveagent.prechat.findorcreate.map.isExactMatch:Asset"
        value="Telephone_Number__c,true" />
        
      <!-- Look up the Account via the Asset record with AccountId-->
????


       
        <!-- Create a Case every time -->
    <input type="hidden" name="liveagent.prechat:caseOrigin" value="Chat" />
    <input type="hidden" name="liveagent.prechat.findorcreate.map:Case" value="Origin,caseOrigin;FullName,FullNameDetail;Phone,PhoneDetail;Email,EmailDetail" />
    <input type="hidden" name="liveagent.prechat.findorcreate.map.doCreate:Case" value="Origin,true;FullName,true;Phone,true;Email,true;" />
    <input type="hidden" name="liveagent.prechat.findorcreate.saveToTranscript:Case" value="Case" />
    <input type="hidden" name="liveagent.prechat.findorcreate.showOnCreate:Case" value="true" />
    
    <!-- Link the Account to the Case -->
    <input type= "hidden" name="liveagent.prechat.findorcreate.linkToEntity:Account" value="Case,AccountId" />

      <input type='submit' value='Request Chat' id='prechat_submit'/> 
<style type="text/css"> 
p {font-weight: bolder } 
</style> 
</form> 
</apex:page>

 
KRayKRay
<input type="hidden" name="liveagent.prechat.query:FullNameDetail"  value="Account,Account.Telephone_Number__c />

This should query the account object using the Phone Number field. It'll put the Account in "FullNameDetail" tag