setServicePresenceStatus

Sets an agent’s presence status to a status with a particular ID. In API version 35.0 and later, we log the user into presence if that user is not already logged in, so you don’t have to make additional calls. You also can use this method to reconnect to Omni-Channel after a connection error.

Syntax 

1sforce.console.presence.setServicePresenceStatus(statusId:String,
2      (optional) callback:function)

Arguments 

NameTypeDescription
statusIdStringThe ID of the presence status you want to set the agent to. Agents must be given access to this presence status through their associated profile or permission set.
callbackfunctionJavaScript method to call when the agent’s status is changed to the presence status associated with statusId.

Sample Code–Visualforce 

1<apex:page>
2    <apex:includeScript value="/support/console/68.0/integration.js"/>
3    <a href="#" onClick="testSetStatus('0N5xx00000000081');return false;">Set Presence Status</a> 
4
5    <script type="text/javascript">
6        function testSetStatus(statusId) {
7
8            //Sets the user’s presence status to statusID. Assumes that the user was assigned this presence status through Setup.
9            //These values are for example purposes only
10            sforce.console.presence.setServicePresenceStatus(statusId, function(result) { 
11                if (result.success) { 
12                    alert('Set status successful');
13                    alert('Current statusId is: ' + result.statusId);
14                    alert('Channel list attached to this status is: ' + result.channels); //printout in console for lists
15                } else {
16                    alert('Set status failed');
17                }
18           }); 
19        }
20    </script>
21</apex:page>

Response 

This method is asynchronous so it returns its response in an object in a callback method. The response object contains the following properties:

NameTypeDescription
successBooleantrue if setting the agent’s status was successful; false if setting the agent’s status wasn’t successful.
statusNameStringThe name of the agent’s current presence status.
statusApiNameStringThe API name of the agent’s current presence status.
statusIdStringThe ID of the agent’s current presence status.
channelsJSON string of channel objectsReturns the IDs and API names of the channels associated with the presence status.