Virtual Agent current interaction record via script

Sean C
Mega Guru

Is there a method to get the current Virtual Agent [Interaction] record in a virtual agent script?

I am trying to access the current interaction record at the end of a conversation to determine if a live chat has occurred or not (based on assigned to either being the Virtual Agent Bot or a real person)

So far i have tried the obvious stuff based on the documentation out there,but nothing specifically mentions this capability.

The 'current' and 'vaSystem' objects do not appear tied directly to the interaction unless i'm accessing them incorrectly

 

Anyone ran into a similar situation and solved this?

 

[Update]

vaVars._interaction_record_sysid will give you the interaction sys_id

and

vaVars.global_vCurrentTopicId will get you the current conversation id

1 ACCEPTED SOLUTION

I updated the main topic with a solution, thanks for the help everyone

View solution in original post

18 REPLIES 18

I thought about doing this, but we are using both authenticated as well as guest chat. There could be some guest scenarios where this could get mixed up. Great point though, this would work for anyone only allowing authenticated chats.

Mark Roethof
Tera Patron
Tera Patron

Maybe a new thought.

If I apply vaVars._topic_current, the output will for example be:

{"sys_id":"20708a612f425010b0c2d5ea2799b6e7","task":"577ceaf12f0e9010b0c2d5ea2799b697","entities":null,"modelId":null,"name":"test test","prediction":null,"title":"test test","type":"normal","utterance":""}

You could use JSON.parse(vaVars._topic_current).task to parse the task.

So I'm wondering what "task":"577ceaf12f0e9010b0c2d5ea2799b697" might be. This sys_id matches the document_id field of a the record in table interaction_log. The interaction_log has a reference to the actual interaction.

Tested this twice, and could trace the correct interaction this way.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Good find!

Knowing this extra roundabout-y method (not sure how you came across the undocumented vaVars._topic_current in the first place...), I'm further convinced that there's gotta be a direct and straightforward way to get to the Interaction from the current conversation. It just doesn't make sense. I really wish we had some ServiceNow input on this... @Nabil Asbi @darius.koohmarey 

A while ago I was searching for how to get the current topic sys_id. After some digging, I came across vaVars._topic_current. I will be finishing an article on this weekend so I can publish it on the community Monday or Tuesday.

Just looked at vaVars._topic_current today again, and noticed the task sys_id. Just had to do a bit of search where that sys_id did match.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Did you have to do anything special to set this up?

I tried pasting it in a VA script, but 'vaVars._topic_current' is coming up undefined

(function execute() {
    var db= vaVars._topic_current;

    gs.log('DEBUG OUTPUT//__ ' + db);
})()

Log Output: 13:34:43.271 DEBUG OUTPUT//__ undefined