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
SteveAtGFISteveAtGFI 

How can I query an existing case number in live agent?

I'm attempting to lookup existing case numbers for live agents if a customer provides a case number. I'm doing this in my code, but it doesn't appear to work. Is there something else I have to do? I've placed the code below and bolded the line where I believe this should be working?

 

<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'>
    Last Name: <input type='text' name='liveagent.prechat.name' id='prechat_field' /><br />
    Email Address: <input type='text' name='liveagent.prechat:Email' /><br />
    Previous Case Number (if applicable): <input type='text' name='liveagent.prechat:CaseNumber' /><br />
    Product: <select name="liveagent.prechat.buttons">
        <option value="573C0000000Gmli">TestProduct</option>
    </select><br />

<!-- Creates an auto-query for a matching Contact record’s Email field based on the value of the liveagent.prechat:Email field -->
<input type="hidden" name="liveagent.prechat.query:Email" value="Contact,Contact.Email"/>
<input type="hidden" name="liveagent.prechat.query:CaseNumber" value="Case,Case.CaseNumber"/>
<input type="hidden" name="liveagent.prechat.save:Email" value="Email__c" />
<input type='submit' value='Request Chat' id='prechat_submit'/>
<style type="text/css"> p {font-weight: bolder } </style>
</form>
</apex:page>

 

Thomas R.ax1441Thomas R.ax1441

I copied your highlight lines into my form. it is working

 

 

=======================================

<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><br/><br/>
<form method='post' id='prechatForm'>
<!-- Field Mapping between prechat form and salesforce
     Name         : Account.Name
     Email Address: Account.PersonEmail
     Product Model: Model__c.Name
     Issue Description: Case.description
-->
<table border = "1" cellpadding="1">
<tr><th>Field Name</th><th>Field Value</th><th>Field Mapping</th>
</tr>
<tr><td>Name</td><td><input type='text' name='liveagent.prechat:Name' id='prechat_field' /></td><td>Account.Name</td>
</tr>
<tr><td>Email Address</td><td><input type='text' name='liveagent.prechat:Email' /></td><td>Account.PersonEmail</td>
</tr>
<tr><td>Product Mode</td><td><input type='text' name='liveagent.prechat:Modle' /></td><td>Model__c.Name</td>
</tr>
<tr><td>Previous Case Number (if applicable)</td><td><input type='text' name='liveagent.prechat:CaseNumber' /></td><td>Case.CaseNumber</td>
</tr>
<tr><td>Issue Description</td><td><input type='text' name='liveagent.prechat:Issue' /></td><td>Case.description</td>
</tr>

</table>
<input type="hidden" name="liveagent.prechat.query:Email" value="Account,Account.PersonEmail" />
<input type="hidden" name="liveagent.prechat.query:Modle" value="Model__c,Model__c.name" />
<input type="hidden" name="liveagent.prechat.query:CaseNumber" value="Case,Case.CaseNumber"/>
<input type="hidden" name="liveagent.prechat.save:Issue" value="Issue__c" />
<input type="hidden" name="liveagent.prechat.save:Email" value="Email__c" />
<!--<input type="hidden" name="liveagent.prechat.save:Issue" value="Case,Case.Subject"/>-->
<input type='submit' value='Request Chat' id='prechat_submit'/>

</form>
</apex:page>

=======================================.

SFDCMattSFDCMatt

I have the exact same problem as Thomas R. I can't explain why this isn't working, it's following the developer guide for Live Agent exactly. Code below for my Pre-Chat form, I've even hard-coded a Case Id, and it's still not querying anything. Each time I go through this pre-chat form, all it does is pop up a Create New Case page, and asks me to select a Record Type.

 

The lines in question are bold / italics. Can anyone explain why this doesn't work? What am I missing?

 

<apex:page controller="PreChatController" showHeader="false" id="page">
<script type="text/javascript">

    (function() {
        function handlePageLoad() {
            var endpointMatcher = new RegExp("[\\?\\&]endpoint=([^&#]*)");
            setToAction = endpointMatcher.exec(document.location.search)[1];
        } 
        if (window.addEventListener) {
            window.addEventListener('load', handlePageLoad, false);
        } else { 
            window.attachEvent('onload', handlePageLoad, false);
        }
    })();
    
    function setAction() {
            document.getElementById('page:preChatForm').setAttribute('action', decodeURIComponent(setToAction));
            document.forms["page:preChatForm"].submit();
    }
    
    function validate() {
        
        return false;
    }
    
</script>
    <apex:form id="preChatForm">
    <apex:actionFunction name="submitCase" action="{!submitCase}"/>
        <apex:pageblock title="Pre Chat Form" rendered="{!!isSuccess}">
            <apex:pageBlockSection columns="1" title="Case Details">
                <apex:inputHidden value="{!newCase.origin}"/>
                <apex:repeat value="{!Fields}" var="caseField">
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel value="{!lablesMap[caseField.Label]}"/>
                        <apex:inputField value="{!newCase[caseField.fieldPath]}" required="{!caseField.required}" />
                    </apex:pageBlockSectionItem>
                </apex:repeat>
                
                <input id='caseId' type='hidden' name='liveagent.prechat:CaseId' value='500e0000001cbko' />
                <input id='caseSearch' type='hidden' name='liveagent.prechat.query:CaseId' value='Case,Case.Id' />


                <apex:pageBlockSectionItem >
                     <apex:commandButton value="Submit" action="{!submitCase}" reRender="preChatForm" style="margin-left:300px;"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageblock>
         <apex:outputPanel rendered="{!isSuccess}" >
                <script>
                    setAction();
                </script>
         </apex:outputPanel>
    </apex:form>
</apex:page>