logo

NJP

Virtual Agent - How to switch Topics

Import · Apr 30, 2019 · article

Hi All,

So I was tasked with building a default topic for virtual agent, we set it as default, however when it ended it always kicked us to the default servicenow "choose your topic" flow... I needed to find a way around this. Digging through ServiceNows _handler workflow I found the following command:

This command expects the name of the topic you wish to switch to, for example:

vaSystem.switchTopic('Check IT Ticket Status')

This meant I could now loop back to the start of my default topic before hitting the "End" of the flow.

Another use I had for this was building a default topic where the customer could choose their topic and not have a text input.

I did this with an topic I called flow_start

The first User input is a a reference choice called "Topic List" which ran the following script for the Choice list setting to get the list of active Topics:

(function execute() {
var options = [];
var gr = new GlideRecord('sys_cs_topic')
gr.addEncodedQuery('active=true^is_system_topic=false^nameNOT LIKE_PRVW')
gr.query();
while (gr.next()) {
options.push({ 'value': gr.name.getDisplayValue(), 'label': gs.getMessage(gr.name) });
} 
    return options;    
})()

This allows the user to choose the topic which then gets handled by a Script action to perform the redirect running the following code:

(function execute() {
    vaSystem.switchTopic(vaInputs.topic_list)
})()

I had seen a few people ask this question, so just wanted to provide what I had found as a work around.

**** THIS WAS DISCOVERED IN MADRID, PER COMMENTS BELOW IT DOES NOT APPEAR TO FUNCTION IN LONDON****

Labels:

image

View original source

https://www.servicenow.com/community/developer-articles/virtual-agent-how-to-switch-topics/ta-p/2310742