How does vaSystem.connectToAgent() work in ServiceNow Virtual Agent and can we do any logic in a Virtual Agent Topic after an agent has accepted the chat?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2021 06:25 PM
I use the vaSystem.connectToAgent() method call to connect a conversation to an agent.
But I am unsure about the nature of this call. I first supposed that it was synchronous, so I thought I could do something like this -
gs.info("-----Connecting----");
var some = vaSystem.connectToAgent();
gs.info("-----Connected-----");
var gr = new GlideRecord('interaction');
gr.get(vaVars._interaction_record_sysid);
gs.info("state = " + gr.getValue('state'));
gs.info("assignment = " + gr.getValue('assignment_group'));
gs.info("-----Connecting----");
var some = vaSystem.connectToAgent();
gs.info("-----Connected-----");
gs.info("----Sleeping 20 seconds-----");
gs.sleep(20000);
gs.info("----Sleep completed-----");
var gr = new GlideRecord('interaction');
gr.get(vaVars._interaction_record_sysid);
gs.info("state = " + gr.getValue('state'));
gs.info("assignment = " + gr.getValue('assignment_group'));
- Labels:
-
Virtual Agent

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2021 08:40 AM
Hi Wesley,
post connected to live agent the topics will not take effect. one of the option to get the group is using this script vaVars._interaction_record_sysid, this returns the sysid you can glide through the interaction record and you can get the group name.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2021 07:49 AM
Murali,
I already did that in my script, and as you can see it returned 'null' for the assignment group.
I wish ServiceNow improves their documentation on this subject, and many others.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2021 09:00 AM
Not sure if you have tried from portal but it works for me. This below is used in text response,
I tried to return the sysid as output text and it works, above is the code.
if you use vaContext and try "Test" option it wont work, you have to test this kind of scenario from VA widget or agent chat in portal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2021 09:06 AM
Yes, I can get the interaction ID using that method, but I cannot get the assignment group for that interaction within the virtual topic script where connectToAgent() is called.
So effectively I have no way of knowing the assignment group in a virtual topic script.