How to switch Topics using topicDiscovery()

Vishal Sharma3
Tera Contributor

I am using switchtopic() to switch topics but When I use this function, Option to start a new conversation is not coming in virtual agent. See below image: 

 

find_real_file.png

 

Now, I want to use topicDiscovery() to switch the Topics but I do not know the exact syntax and procedure to use the same. Can anyone please help me that how do we use topicDiscovery() to switch to specific topics?

@Mark Roethof 

1 ACCEPTED SOLUTION

Basically it's just what's mentioned in this article:
50+ (Un)documented Virtual Agent variables (vaInputs, vaVars, vaContext, vaSystem)

Or just example script:

(function execute() {

    vaVars.global_search_text = 'Topic Name to Switch to';
    vaSystem.topicDiscovery();

})()

Be aware: Name of the topic, not sys_id!

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

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

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

View solution in original post

7 REPLIES 7

Basically it's just what's mentioned in this article:
50+ (Un)documented Virtual Agent variables (vaInputs, vaVars, vaContext, vaSystem)

Or just example script:

(function execute() {

    vaVars.global_search_text = 'Topic Name to Switch to';
    vaSystem.topicDiscovery();

})()

Be aware: Name of the topic, not sys_id!

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

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

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Any follow-up needed? Or was my answer sufficient?
Let me know.

If your question is solved, please close the topic by marking my answer as correct. This will help others searching for a similar question and will remove the topic from the unsolved list.

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

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

Chris D
Kilo Sage
Kilo Sage

Hi, switchTopic() shouldn't be used anymore and neither should topicDiscovery()* - you should use vaSystem.switchTopicById('[sys_id of sys_cs_topic]').

See Virtual Agent scripts (servicenow.com) for details - and note switchTopic isn't even there anymore. Back in Orlando, switchTopic was the only option, but it had technical limitations, most notably not being able to start a new conversation after it, but luckily ServiceNow added the new method.

*topicDiscovery() may still have some use cases but switching to another known topic is NOT a good idea. TopicDiscovery is going to trigger NLU which is an absolute waste of resources for switching to a topic that you know already exists. The whole point of NLU/Topic Discovery is to check if an appropriate topic exists. Besides being inefficient, switching topics with topicDiscovery() introduces a) delay for the user (possibly under a second, but possibly more depending on your NLU model complexity) and b) the very real risk of NLU breaking and breaking your topic switch. We've used topicDiscovery() in the past and have seen both of these issues.

p.s. I just submitted an idea No-Code Topic Switch Utility for Virtual Agent Designer to make topic switching even easier - this is an incredibly common question that VA admins new and old and I'd ask for your upvote 🙂