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
Devangana TarafdarDevangana Tarafdar 

Taking action on Omnichannel accept event

Hello,

I have created a console app in my development enviroment to learn more about omnichannel. I need to take some action when an agent accepts a case. I am able to see cases (assigned to my queue) popping up on the omnichannel widget with the accept link so the routing part is working.

I next created a visualforce page with the following code:
(After going through the salesforce integration toolkit)

<apex:page >
<script type="text/javascript">
    var showAlert = function (result) { alert("Accepted with result message " + result.message); }
    window.onLoad = function() {  sforce.console.addEventListener(sforce.console.ConsoleEvent.PRESENCE.WORK_ACCEPTED, showAlert); }
  </script>

</apex:page>

But when I accept a case by clicking accept, nothing happens. I am clearly doing it wrong.

How can I  "catch" the omnichannel accept action ?

I am new to both salesforce dev and javascript, any suggestions regarding the right course of action would be helpful.

Thanks,

Devangana

sharathchandra thukkanisharathchandra thukkani
try below code:

<apex:page showHeader="false" sidebar="false" standardStylesheets="false" applyHtmlTag="true" applyBodyTag="true" docType="html-5.0">
<html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">

<head>
    <title>ChatAlert</title>
    <apex:includeScript value="/support/console/40.0/integration.js"/>
    <apex:includeScript value="{!URLFOR($Resource.jquery_ui, 'js/jquery-1.6.2.min.js')}" />
</head>

<body>
</body>

<script>
$(document).ready(function(){
 sforce.console.addEventListener(
            sforce.console.ConsoleEvent.PRESENCE.WORK_ACCEPTED,
            function (result) {
                console.log('Accepted work item: ', result);
                alert(result.workItemId);
            });
});
</script>
</html>
</apex:page>