Virtual Agent not redirecting to same topic if user tries to utter same utterance again .!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2023 01:40 PM
Hi Experts,
Can anyone help me in comparing the current topic and the topic returned by the utterance uttered by user.
The virtual agent not recommending the same topic if user again utters the same intend .
var topicCurrent = JSON.parse(vaVars._topic_current);
var topicName = topicCurrent.name.trim();
gs.info("Current Topic Name: " + topicName);
var searchTopic = vaSystem.switchTopic(vaSystem.getSearchText().trim());
gs.info("Search Topic Name: " + searchTopic.name.trim());
if (topicName === searchTopic.name.trim()) {
gs.info("Matching topic found.");
return searchTopic;
} else {
gs.info("No matching topic found. Falling back to 'A.V.A Search Fallback topic'.");
return vaSystem.switchTopic('A.V.A Search Fallback topic');
}
The above code always takes the else part .
Please provide your inputs.
Thanks in advance!.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2023 08:40 PM
Hi there,
When debugging searchTopic, topicName, what value do you get? Is it the expected value? Or is it already going wrong at one of these two?
I do notice you are using vaSystem.switchTopic on two places in your script. .switchTopic is outdated since a few releases, use .switchTopicById or .switchTopicByName
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2023 10:39 PM
HI @Hemachithra ,
I trust you are doing great.
Here's a user-friendly and professional solution for your ServiceNow query:
var topicCurrent = JSON.parse(vaVars._topic_current);
var topicName = topicCurrent.name.trim();
gs.info("Current Topic Name: " + topicName);
var searchTopic = vaSystem.switchTopic(vaSystem.getSearchText().trim());
gs.info("Search Topic Name: " + searchTopic.name.trim());
if (topicName === searchTopic.name.trim()) {
gs.info("Matching topic found.");
return searchTopic;
} else {
gs.info("No matching topic found. Falling back to 'A.V.A Search Fallback topic'.");
return vaSystem.switchTopic('A.V.A Search Fallback topic');
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2023 10:58 PM - edited 07-01-2023 11:00 PM
Where is the difference between the code of the one posting this question and yours? I only see a difference on two blanc lines removed 🤔
Also note:
".switchTopic is outdated since a few releases, use .switchTopicById or .switchTopicByName"
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2023 07:27 AM
Hi @Mark Roethof ,
How can we get the topic name from the user input ?
I have fetched the user input using the below system method.
vaSystem.getSearchText().trim()