Can we dynamically show "position in queue" to user in virtual agent
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2025 04:46 PM
I have configured the queue count during a live agent transfer in the Virtual Agent and displayed it as a system message using the script below. However, I am looking for options to dynamically track and update this count in real time. Is there a way to achieve this?
(function execute() { var VALq = new GlideAggregate('awa_interaction_work_item'); VALq.addEncodedQuery("wi_active=true^wi_state=queued"); VALq.addAggregate('COUNT'); VALq.query(); if (VALq.next()) { var countAgent = VALq.getAggregate('COUNT'); } var msg = "Your current queue position is: " + countAgent; vaSystem.sendSystemMessage(msg) })()
- Labels:
-
Agent Chat
-
live agent chat
-
Virtual Agent
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2025 05:31 PM
I would love to know this too, as someone has just asked me if this is possible. I looked at your script and Copilot suggested the following instead (I'm not proficient with coding hence my reliance on AI....):
----
To show the user's queue position: You need to:
- Query all active, queued work items, sorted by creation (e.g., sys_created_on).
- Loop through them and find the position of the current user's work item (using a unique identifier, e.g., sys_id or user reference).
Example (assuming you have the current work item's sys_id as currentSysId):
(function execute() {
var currentSysId = /* set this to the current work item's sys_id */;
var gr = new GlideRecord('awa_interaction_work_item');
gr.addEncodedQuery("wi_active=true^wi_state=queued");
gr.orderBy('sys_created_on');
gr.query();
var position = 1;
var found = false;
while (gr.next()) {
if (gr.getValue('sys_id') == currentSysId) {
found = true;
break;
}
position++;
}
var msg;
if (found) {
msg = "Your current queue position is: " + position;
} else {
msg = "Your work item is not currently in the queue.";
}
vaSystem.sendSystemMessage(msg);
})();
Note:
- Replace currentSysId with the actual sys_id of the user's work item.
- This script will send the user's actual position in the queue, not just the total count.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2025 06:07 PM
Also, where are you adding this script in the topic in relation to the transfer to live agent script?