+ Start a Discussion
Dev2IndiaDev2India 

Pre populate Portal user name and email in Live Agent Pre-Chat Form

We have implemented the live Agent functionality in Production. We have also our portal users for whome this chat functionality provided. Through portal home page , clients can initiate chat (chat button provided on portal). Also we have implemented the Prechat form in order to receive the data like Name, email, Account..

 

This is working fine but clients needs to fill out these details in Prechat form, which is not feasible since they are Portla users. So I am prepopulating these details like name, email in Pre chat form. Used prety simple code at VF (mentioned below) , this is working fine in Salesforce preview. However, when used on Portal , prechat form is not reflecting the correct Name , email in Pre chat form. In the name field this is reflecting Sitename and in email email this is using the by default site user email id.

 

We want when, every client logged in Portal and initiating the chat , in prechat form , Client name and email should be in user context....

 

Please let me know any workaround / solution how to resolve this.

 

I will really appreciate this ....

 

<apex:page showHeader="false" standardController="User" >

    <script>
        function clickBtn()
        {
            var btnSubmit = document.getElementById('prechat_submit');
            btnSubmit.click();
        }
    </script>

    <!-- 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'>
   
        <style type="text/css">
            body {
                margin: 0 auto;
                padding: 0;
                font-family: 'Trebuchet MS', Helvetica, sans-serif;
                font-size: 12px;
                color: #737373;
                line-height: 16px;
            }                   

            p {
                font-weight: bolder
            }
           
            td {
                font-family: 'Trebuchet MS', Helvetica, sans-serif;
            }
           
            h1 {
                font-family: 'Trebuchet MS', Helvetica, sans-serif;
            }

            .btnClass {
                font-family: 'Trebuchet MS', Helvetica, sans-serif;
            }

        </style>

        <!-- Creates an auto-query for a matching Contact record’s Email field based on the value of the liveagent.prechat:Email field -->   
        <table border="0" width="400px">
            <tr>
                <td>
                    <b>Name: </b>
                </td>
                <td>
                    <input type='text' size="40" name='liveagent.prechat:Name' id='prechat_field' value='{!$User.FirstName} {!$User.LastName}' />          
                </td>
            </tr>
            <tr>
                <td>
                    <b>Email Address: </b>
                </td>
                <td>
                    <input type='text' size="40" name='liveagent.prechat:Email' width="500" value='{!$User.Email}' />
                </td>
            </tr>
            <tr>
                <td>
                    <b>Property Name: </b>
                </td>
                <td>
                    <input type='text' size="40" name='liveagent.prechat:Account' value='{!getAccountName}' />
                </td>
            </tr>
            <tr>
                <td>
                   
                </td>
                <td align="center">
                    <input type='submit' value='Request Chat' id='prechat_submit' class="btnClass" />
                </td>
            </tr>
        </table>

        <input type="hidden" name="liveagent.prechat.query:Email" value="Contact,Contact.Email" />        

    </form>


</apex:page>

 

Thanks alot !!!!

 

dho1dho1
Hi, Did you get any answers on this? Thanks!
Varma PalapalaVarma Palapala
The way to do this is modifying the section where deployment code is added. Please ensure to add the below lines just before liveagent.init(....)

liveagent.addCustomDetail('Name', '{!$User.FirstName}{!$User.LastName}');
liveagent.addCustomDetail('UserEmail', '{!$User.Email}');
Larry Caper II 7Larry Caper II 7
@varmapalapala does this work for the new Snap-In feature? Would like to autopopulate the pre-chat form with the Community User's First Name, Last Name and Email. 
Atul Gupta 46Atul Gupta 46
@Larry - I am also looking for solution to autopopulate the pre-chat form with the Community User's First Name, Last Name and Email in Snap-In. Did you hear something? Please share the details if you get something. Thanks!!
Chris Robertson 2Chris Robertson 2
@Larry Were you able to get the snap in pre-chat form to pre-populate with first name, last name, and email?  Thanks!
Larry Caper II 7Larry Caper II 7
@Chris & @Atul - I was not successful in finding a viable solution to automatically populate (or bypass the pre-chat form) leveraging the community user's first, last and email. Have you guys found a solution for this?
Chris Robertson 2Chris Robertson 2
@Larry  i actually got two different responses from 2 different folks on the community product team at SFDC.  The first one said that you could do it by leveraging the live agent API, and the 2nd person siad it couldn't be done.  Unfortunately, it seems that the 2nd person was correct.  However, I've been told that in Winter 18 the live chat window will automatically pre-populate for authenticated users.  Of course, safe harbor applies.
Sarah PariseSarah Parise
Has anyone been able to try this out with the Winter 18 preview releases. 
Jeffrey KoJeffrey Ko
Did anyone find a solution or workaround to get the snap-in pre-chat form to pre-populate with first name, last name, and email?  I didn't see this in Winter '18 ... thanks!  :)
Jayesh JunejaJayesh Juneja

This is what I used to get the info pre-populated for logged-in users (worked for me) :

embedded_svc.settings.prepopulatedPrechatFields = {
        FirstName: "<%= User&.current_user&.contact&.first_name %>",
        LastName: "<%= User&.current_user&.contact&.last_name %>",
        Email: "<%= User&.current_user&.email %>",
        Phone: "<%= User&.current_user&.phone_mobile %>"
       };