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
Haystack CertifiedHaystack Certified 

Set Live Agent online automatically when starting console

I am trying to use the console integration kit to automatically set the user to online for Live Agent when they start the service cloud console.  Below is my code for a footer component.  It has two ways to set the agent status.  The first is near the bottom of the script where the function to set online is automatically run when the page loads.  The second is a link that the user can click.

There seems to be a timing problem.  The function does run automatically, but it seems to run before the Live Agent component initializes.  I am guessing that my function sets the agent online and then the Live Agent component resets to offline.

I think it is a timing problem because using the link after everything has started does sets the agent online.

Is there an event I can listen for or something else that allows my component to wait until everything is initialized?
<apex:page showHeader="false" sidebar="false">
    <apex:includeScript value="/support/console/29.0/integration.js"/>

    <a href="#" onClick="fnSetAgentState('Online');return false;">Set Agent Status to Online</a> 

    <script type="text/javascript">
        function fnGetAgentState() {
            sforce.console.chat.getAgentState(function(result) {
                if (result.success) {
                    alert('Agent State: ' + result.state);
                } else {
                    alert('getAgentState has failed');
                }
            });
        }
    
        function fnSetAgentState(state) {
            sforce.console.chat.setAgentState(state, function(result) {
                if (result.success) {
                    fnGetAgentState();
                } else {
                    alert('Live Agent: SetAgentState has failed');
                }
            });
        }
        
        fnSetAgentState('Online');
    </script>
</apex:page>


Chris MollanChris Mollan
Hi,
I know this is a tad old, but did you ever get this working?  I'm looking for a way for Live Agent to default to online automatically.

Thanks
Haystack CertifiedHaystack Certified
The only solution I came up with for the timing problem was to put a time delay on it.  Replace fnSetAgentState('Online'); with setTimeout("fnSetAgentState('Online')", 5000);  BTW, this was never deployed so it's not tested in a production environment.
Christine_KChristine_K
Just curious if there is a lightning component equivelent which works with omni channel?