+ Start a Discussion
TylerBrooksTylerBrooks 

Display javascript in a VF page without pressing a button

I want to have a user's current omnichannel status on a visualforce page displayed as our servers kick users out of omnichannel and they don't realize so I would like to have their status always displayed.

I have this button that gets the status and alerts the status in an alert window but I just want the status to be displayed without them having to click the button.

Here is my code currently:
 
<apex:page>
    <apex:includeScript value="/support/console/45.0/integration.js"/>
    <a href="#" onClick="testGetStatusId();return false;">Get Omni-Channel Status</a>
    
    <script type="text/javascript">
        function testGetStatusId() {
            sforce.console.presence.getServicePresenceStatusId(function(result) {
                if (result.success) {
                    alert('Status is: ' + result.statusName);
                } else {
                    alert('Current Status is Offline');
                }
            });
        }
    </script>
</apex:page>

Can anyone tell me how to just return the status without clicking the button?
GovindarajGovindaraj
Hi Tyler,

Try call that function onLoad.
<apex:page>

<script language="javascript"> 
function init() {  
     //Logic
} 
</script>

<body onload="init()"> 
     //Logic
</body>

</apex:page>
Thanks,
Govindaraj.S
GovindarajGovindaraj
Hi Tyler,

Please keep this community clean by closing the solved cases.

Thanks,
Govindaraj.S