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?

Wesley Falcao
Tera Contributor

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'));
 
However, this did not work. The assignment group was null. The system log showed the following - 
 
find_real_file.png
 
Then I added a delay after connectToAgent(), to give myself enough time to 'Accept' the conversation as an agent - 
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'));​
 
However, this did not have the intended effect. To my surprise, I noticed that the connection to the agent was delayed by 20 seconds, and not merely the part of the script after connectToAgent(). The system log showed the following - 
find_real_file.png
 
So how does connectToAgent() work and is it feasible to run some custom logic after it has run? Thus far I have observed that adding another 'Script' action after the Script that connects to an agent has no effect. My end goal is to get the assignment group that the interaction record is assigned to.  
 
4 REPLIES 4

Muralidharan BS
Mega Sage
Mega Sage

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

 

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. 

Not sure if you have tried from portal but it works for me. This below is used in text response, 

 

find_real_file.png

I tried to return the sysid as output text and it works, above is the code. 

find_real_file.png

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. 

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.