+ Start a Discussion
FinnArildFluidoFinnArildFluido 

Live Agent Peculiarities.

I am sometimes amazed how a seemingly simple thing is some times made unneccessary difficult. Say you want to start a Live Agent session and have an input field to type an email address in right away without bothering the user with a pre-chat form. Should be as simple as the following code, right?: 

 

<html>
    <head>
	<!-- THIS NEEDS TO BE INCLUDED FOR EVERYTHING TO WORK -->
	<script type='text/javascript' src='https://c.la1c1.salesforceliveagent.com/content/g/deployment.js'></script>
	<script type='text/javascript'>
	liveagent.init('https://d.la1c1.salesforceliveagent.com/chat', '572D0000000011K', '00DD0000000oGsq');
	</script>
	<!-- END INCLUDE -->
    </head>
    <body>
	<!-- THIS IS JUST THE HEADER OF THE PAGE -->
	<h1>Chat med en kundebehandler!</h1>
	
	<!-- HERES THE BUTTON CODE FROM SF. ADD CONTENT WHERE THE COMMENT IS -->
	<div id="liveagent_button_online_573D0000000016a" style="display: none;" >
	    <input type="text" name="email" id="chatter_email" onBlur="emailUpdate()"/><br/>
	    <a href="javascript&colon;//Chat" onclick="liveagent.startChat('573D0000000016a')">Fyll inn din e-post og trykk her for å chatte</a>
	</div>
	<div id="liveagent_button_offline_573D0000000016a" style="display: none;">Kundebehandler offline</div>
	<script type="text/javascript">
	    if (!window._laq) { window._laq = []; }
	    window._laq.push(function()
		{liveagent.showWhenOnline('573D0000000016a', document.getElementById('liveagent_button_online_573D0000000016a'));
		liveagent.showWhenOffline('573D0000000016a', document.getElementById('liveagent_button_offline_573D0000000016a'));
	    });
	    function emailUpdate() {
		liveagent.addCustomDetail('Contact E-Mail', document.getElementById('chatter_email').value).map('Contact', 'Email', true, true, false);
		
	    }
	</script>
	<!-- END OF BUTTON CODE -->
    </body>
</html>

 But no - you get a javascript exception: "you cannot add a detail after page initialization".

 

In practice this means that you can add whatever you like before you load the page, but if you want the user to input something - you're ... toast (that was not the word I wanted to use, so I leave that up to your imagination). 

 

Stuff like that irritates me like a red hot poker up the butt.

 

Thanks for listening :) ...

Sumitkumar_ShingaviSumitkumar_Shingavi
Good observation!
Yaron MeinerYaron Meiner
I found a way to resolve this but it's a bit of a hack. If you add an iframe to a page that can get params and set the vars, you can basically destroy and build the iframe on any change :).

In my case, i built my page in php:
<html>
<head>
</head>
<body>
<script type='text/javascript' src='https://XXXX.salesforceliveagent.com/content/g/js/35.0/deployment.js'></script>

</script>
<script>
<?php foreach($_REQUEST as $key => $value): ?>
  <?php if ( strpos($key,'field-') !== false ): ?>
    liveagent.addCustomDetail('<?php print str_replace("field-","",$key); ?>', '<?php print $value; ?>');
  <?php endif ?>
<?php endforeach;?>
liveagent.init('https://d.la7cs.salesforceliveagent.com/chat', '{some number}', '{someothernumber}');
</script>
<a href="javascript://Chat" id="liveagent_button_online_XXXX" onclick="liveagent.startChat('XXXXX')" style="display: none;">online</a>
<div id="liveagent_button_offline_XXXX" style="display: none;">offline</div>
<script type="text/javascript">
if (!window._laq) { window._laq = []; }
window._laq.push(function(){liveagent.showWhenOnline('XXXX', document.getElementById('liveagent_button_online_XXX'));
liveagent.showWhenOffline('XXXX', document.getElementById('liveagent_button_offline_XXXX'));
});</script>
</body>
</html>

This page actually creates the link on every refresh and the parameters just adds the fields.