Virtual Agent not redirecting to same topic if user tries to utter same utterance again .!!

Hemachithra
Tera Contributor

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!.

 

4 REPLIES 4

Mark Roethof
Tera Patron
Tera Patron

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

https://docs.servicenow.com/bundle/utah-servicenow-platform/page/administer/virtual-agent/concept/vi...

 

Kind regards,
Mark

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

Amit Gujarathi
Giga Sage
Giga Sage

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



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

LinkedIn

Hemachithra
Tera Contributor

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()