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
Adil ShaikhAdil Shaikh 

How to dynamically pass the values from url to live chat form and creating new contact or updating the existing contact based on email id.

Here is sample code:  chat gets initiated by not creating or updating new contact in salesforce.

 

<html>
    <head><title> Live Agent Chat</title></head>
    <body>
        <div id="chat-icon">
            <form>
              <!-- Detail inputs -->
              <p>First Name:</p><input type="text" id="firstName" /><br />
              <p>Last Name:</p><input type="text"  id="lastName" /><br />
              <p>Email:</p><input type="text" id="email" /><br />
              <p>Mvelopes User Name:</p><input type="text" id="mvusrname" /><br />
              <input type="button" value="Submit" onClick="startChat();return false;">
            </form>         
        </div>
        <script type='text/javascript' src='https://c.la4-c1cs-was.salesforceliveagent.com/content/g/js/38.0/deployment.js'></script>
        
        <script type="text/javascript">
            function setName() {
                 document.getElementById("prechat_field").value = "Hellloooo";
                 return true;
            }
            function startChat(){
               liveagent.init('https://d.la4-c1cs-was.salesforceliveagent.com/chat', '572550000004CNP', '00D550000006VyM');
                if (!window._laq) { window._laq = []; }
                window._laq.push(function(){
                    liveagent.enableLogging();
                    liveagent.setChatWindowHeight('720');
                    liveagent.showWhenOnline('573550000004CiS', document.getElementById('liveagent_button_online_573550000004CiS'));
                    liveagent.showWhenOffline('573550000004CiS', document.getElementById('liveagent_button_offline_573550000004CiS'));
                  
                    liveagent.addCustomDetail('First Name', document.getElementById('firstName').value);
                    liveagent.addCustomDetail('Last Name', document.getElementById('lastName').value);
                    liveagent.addCustomDetail('Email', document.getElementById('email').value);

 <input type="hidden" name="liveagent.prechat.findorcreate.map:Contact" value="FirstName,firstName;LastName,lastName;Email,email" />
                    <input type="hidden" name="liveagent.prechat.findorcreate.showOnCreate:Contact" value="true" />
                    <input type="hidden" name="liveagent.prechat.findorcreate.showOnCreate:Case" value="true" />
                    <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;Phone,true" />
                    liveagent.addButtonEventHandler('573550000004CiS',function (e){
                    if(e == liveagent.BUTTON_EVENT.BUTTON_AVAILABLE){              
                            liveagent.startChat('573550000004CiS');
                        }       
                    });
                });

            }
        </script>
    </body>
</html>