Unable to fetch the value from Static Choice and Pass in other topic

pandeyved
Tera Contributor

Hi All,
I need help in one use case in Virtual Agent.
I am giving one static choice to users and I am trying to store the input from that static choice then I need that value in another topic based on which I will define some conditions.
What I did:
After defining choices, I have included one script Action to store the values:

(function execute() {
vaVars.selectedCategory='';
selectedCategory = vaContext.select_topic_related_to_your_problem;
})()
After this, I have defined the topic Switcher, it is switching perfectly, then in other topic I am trying to fetch the value like this:
(function execute() {
if(vaContext.selectedCategory == 'Software and Apps')
return true;
})()
But it is saying undefined. I am attaching the image. Please Guide Thanks
Topic 1: 
pandeyved_0-1704174817702.png

 

Topic 2:

pandeyved_1-1704174817617.png

 

Thanks
Vedant

1 ACCEPTED SOLUTION

Anil Lande
Kilo Patron

Hi,

Have you create script variables to store the value?

https://developer.servicenow.com/dev.do#!/learn/courses/tokyo/app_store_learnv2_virtualagent_tokyo_v...

 

Update your script action to store value:

(function execute() {
vaVars.selectedCategory= vaContext.select_topic_related_to_your_problem;
})()

try below:

(function execute() {
if(vaVars.selectedCategory == 'Software and Apps')
return true;
})()

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

3 REPLIES 3

Anil Lande
Kilo Patron

Hi,

Have you create script variables to store the value?

https://developer.servicenow.com/dev.do#!/learn/courses/tokyo/app_store_learnv2_virtualagent_tokyo_v...

 

Update your script action to store value:

(function execute() {
vaVars.selectedCategory= vaContext.select_topic_related_to_your_problem;
})()

try below:

(function execute() {
if(vaVars.selectedCategory == 'Software and Apps')
return true;
})()

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

@pandeyved 

We haven't heard from you on this, is your issue resolved?

If yes, would be happy to know the fix/solution.

 

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

Haven't tested, though looking at the code you are sharing the error looks valid to me. You are not setting vaVars.selectedCategory with any value.

 

I am wondering why you are using the topic switcher (I assume this is topicSwitch?), since this is an older method from years ago and Virtual Agent did evolve over the years with newer/better methods.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn