How to pass Value from one topic to another in Virtual Agent

pandeyved
Tera Contributor

Hi All,
I have a requirement of passing a variable from one topic to another topic.
I am defining one variable like this to store the user input:

vaVars.selectedCategory = vaInputs.select_topic_related_to_your_problem;
 Let's say selectedCategory is Hardware.
So I want this variable in another topic:
In another topic I am parsing one system Property like this:
var sysPropertyValue = gs.getProperty('x_4dai_va.connected_content_id');
var sysPropertyObject = JSON.parse(sysPropertyValue);
var topicSysId = sysPropertyObject[selectedCategory];
var options = [];
gs.info("line15"+topicSysId);

But in logs I can see in the second topic where I am fetching the value, it showing selectedCategory is not defined. 
How I can make it work so that selectedCategory should store correct value that is Hardware, to give it's corresponding sysId.
Kindly Guide.
Thanks
12 REPLIES 12

LiveAgent_selectedCategory = vaInputs.select_topic_related_to_your_problem.getValue();

 

This will result in not defined. Because you didn't do so.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

@Mark Roethof So can you please help, how I can write it.
It will be very helpful for me.
Thanks

Basically at the start of your script, your just suddenly mentioning out of the blue:

 

LiveAgent_selectedCategory

 

That's not possible in any ServiceNow scripting. You do need to define it. So also within Virtual Agent scripting. Like:

 

var LiveAgent_selectedCategory = 'blablalba';

vaVars.LiveAgent_selectedCategory = 'blablabla';

vaContext.LiveAgent_selectedCategory = 'blablabla';

 

Etc..

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

Thanks for your time and reply @Mark Roethof 

But you can see here in first topic, I am defining here as:

vaVars.LiveAgent_selectedCategory='';
LiveAgent_selectedCategory = vaInputs.select_topic_related_to_your_problem.getValue();
And in Second topic where I need this Variable's value, I am using it as 
var sysPropertyValue = gs.getProperty('x_4dai_va.connected_content_id');
var sysPropertyObject = JSON.parse(sysPropertyValue);
var topicSysId = sysPropertyObject[vaVars.LiveAgent_selectedCategory];
If am directly using it as LiveAgent_selectedCategory then it is returning as undefined, and if I am using it with vaVars then I am getting as null.
So how to define it in second topic so it should work.

thanks

"So how to define it in second topic so it should work."

 

Using vaContext.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn