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

Chris D
Kilo Sage
Kilo Sage

Sorry don't have a solution (edit: maybe I do? see below) but following this because, now that we're on Orlando, I'll want to know soon how to link VA-created Incidents (specifically scripted ones) to their Interaction and the key to that is identifying the current Interaction... which apparently isn't as straightforward as you mention. Once I have the interaction, I presume it should just be as simple as creating a new interaction_related_record at the end of the incident-creation script.

The only thing I can think of right now is that there's no OOTB link (reference) from Conversation (sys_cs_conversation) to its respective Interaction, but I know there's the inverse of that link: a reference to the Conversation on the Interaction record - the Channel Metadata Table and Channel Metadata Record fields.

If you can get the sys_id of the current Conversation within the Conversation - I presume 'current' is the Conversation record - then you should be able to query the Interaction table and find the one Interaction record with that reference.

I tooled around some more and unfortunately 'current' doesn't appear to be valid in a VA script at all. 

I did not know about the sys_cs_conversation table. I think that is likely what is linked if anything. I notice in the designer when you preview and turn on logging one of the first few logs will always be the referenced sys_cs_conversation record sys_id. Since it's being logged i would hope there's also a way to access it from a script.

I just messed around myself to no avail either >:/

If we can't directly query the related Interaction from within the conversation - which seems like something that should be readily doable, I feel like my method would be the best indirect way to get the Interaction record, but why can't we get the current sys_cs_conversation id?? Or more accurately, how do we get it?

Looking at documentation, I actually got my own original question answered; luckily ServiceNow did make it easy to add a related record via VA scripts:

vaSystem.attachRecordToConversation(String String tableName, String sysId)This method attaches ServiceNow records that are updated or created during a Virtual Agent conversation to the Related Tasks list in a Virtual Agent interaction record.

But at the same time, looking at this, obviously vaSystem knows what its current interaction record is, so we shouldn't even need to be indirectly querying the Interaction via the Conversation ID. I wish VA APIs were better documented...

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Haven't seen any vaSystem etc properties for this. Though you could think of a workaround, 99% solid I think.

Upon opening the Virtual Agent web client, so for example the Virtual Agent widget on the Service Portal, the interaction immediately is created. The interaction is created with Opened for as a reference to the logged in user, and Assigned to as a reference to the Virtual Agent user.
So you could query on this, sorting on the most recent record, and limiting results to 1. 99% solid, unless the same user starts multiple sessions at almost the same time, and with Virtual Agent. Not really likely 🙂

You could use this in your closing setup topic.

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