+ Start a Discussion
Sonal ShrivastavaSonal Shrivastava 

Live Agent liveagent.prechat.buttons not working in pre-chat page

I am creating a pre-chat page for live agent, I have copied the same code from Pre-Chat Form Code Sample mentioned in live agent developer guide, just replaced the button Ids.
I placed one chat button (ID : 573g00000008Ofd) on a VF page for testing with this pre-chat page. On clicking that, the pre-chat form opens. But when the form is submitted it always redirect to this button's custom chat page, regardless of which button I select from the drop down.

<select name="liveagent.prechat.buttons">
<option value="573g00000008Ofd">Chat Button 1 </option>
<option value="573g00000008OfY">Chat Button 2 </option>
</select>

Please let me know if I am missing something or some other code needs to be incorporated to get redirected to respective custom chat pages of the buttons.
 
reymagdaongreymagdaong
hi, can you paste/share the whole html source code? maybe you are also missing the deployment.js thanks.
Sonal ShrivastavaSonal Shrivastava
Here is my code for deployment page and prechat page.

Deployment Page:
----------------------------

<apex:page showHeader="false">
    <!-- Code Copied from Button Configuration -->
    <img id="liveagent_button_online_573g00000008OfY" 
        style="display: none; border: 0px none; cursor: pointer" 
        onclick="liveagent.startChat('573g00000008OfY')" 
        src="https://ccochat-wagcco.cs17.force.com/LiveAgent/resource/1452280193000/Live_Chat_Online" />
        
    <img id="liveagent_button_offline_573g00000008OfY" 
        style="display: none; border: 0px none; " 
        src="https://ccochat-wagcco.cs17.force.com/LiveAgent/resource/1452280187000/Live_Chat_offline" />

    <script type="text/javascript">
        if (!window._laq) { window._laq = []; }
        window._laq.push(function(){
            liveagent.showWhenOnline('573g00000008OfY', document.getElementById('liveagent_button_online_573g00000008OfY'));
            liveagent.showWhenOffline('573g00000008OfY', document.getElementById('liveagent_button_offline_573g00000008OfY'));
        });
    </script>

    <!-- Code Copied from Deployment -->
    <script type='text/javascript' 
            src='https://c.la2w1cs.salesforceliveagent.com/content/g/js/36.0/deployment.js'>
    </script>
    <script type='text/javascript'>
        liveagent.init('https://d.la2w1cs.salesforceliveagent.com/chat', '572g00000008OWR', '00Dg0000006U9Yi');
    </script>
</apex:page>


Pre-Chat Page:
-----------------------

<apex:page showHeader="false" docType="html-5.0">
    
    <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>

    <form id='prechatForm' method='post' >
    
        <apex:pageBlock title="Enter your details">
            <apex:pageblockSection columns="1"  >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="First Name" />
                    <input type='text' name='liveagent.prechat:FirstNameDetail' />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Last Name" />
                    <input type='text' name='liveagent.prechat:LastNameDetail' />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Email Address" />
                    <input type='text' name='liveagent.prechat:EmailDetail' />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Department" />
                    <select name="liveagent.prechat.buttons">                        
                        <option value="573g00000008OfY">Chat Button 1 </option>
                        <option value="573g00000008Ofd">Chat Button 2 </option>
                    </select>
                </apex:pageBlockSectionItem>
            </apex:pageblockSection>        
        </apex:pageBlock> 
                
        <input type="hidden" name="liveagent.prechat:RecordTypeIdDetail" value="012600000005NJJAA2"/>
        <input type="hidden" name="liveagent.prechat.findOrCreate.map:Contact" value="FirstName,FirstNameDetail;LastName,LastNameDetail;Email,EmailDetail;RecordTypeId,RecordTypeIdDetail" />
        <input type="hidden" name="liveagent.prechat.findOrCreate.map.doFind:Contact" value="Email,true" />
        <input type="hidden" name="liveagent.prechat.findOrCreate.map.isExactMatch:Contact" value="Email,true" />
        <input type="hidden" name="liveagent.prechat.findOrCreate.map.doCreate:Contact"
               value="FirstName,true;LastName,true;Email,true;RecordTypeId,true" />
        <input type="hidden" name="liveagent.prechat.findOrCreate.showOnCreate:Contact" value="true" />
        <input type="hidden" name="liveagent.prechat.findOrCreate.saveToTranscript:Contact" value="ContactId" />
        
        <input type='submit' value='Request Chat' id='prechat_submit'/>
               
    </form>    
</apex:page>


 
reymagdaongreymagdaong

hi,
did you try to create/open this as an independent html?
as i understand it you are trying to do this?
https://developer.salesforce.com/docs/atlas.en-us.live_agent_dev.meta/live_agent_dev/live_agent_direct_to_agent_fallback_in_prechat_form.htm

Sonal ShrivastavaSonal Shrivastava
Hi,
I have tested with deployment HTML page, it is working in the same way. However, I did not try with prechat HTML page, since we are using force.com site. So I have given Pre-Chat Form Page as this prechat VF page. 
As I understand, I will have to give the prechat URL in chat button if I create an independent HTML page for pre chat form. But I am not getting where will I host this prechat HTML page so that I can give its url in the chat button setting.

And yes, my requirement is to route the chat to appropriate agent after collecting the information from prechat form. Can you suggest on the same.

Thanks!
john harvey 2john harvey 2
Hi Sonal,

Di you find solution on how or where to host pre chat form to transfer the info to the agent? I am having hard time figuring out that.