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

Mark Roethof
Tera Patron

Hi there,

 

Instead of vaVars, you could try to use Context Variables.

 

From the Docs:
"They work in a global scope whereas system variables work within the scope of the topic. You can use context variables anywhere in the conversation using the vaContext object."

Thanks @Mark Roethof 

@Mark Roethof 
I have tried that also. 
First in conversational Interface I defined the variable called LiveAgent_selectedCategory

then in first topic: 
I have used:

(function execute() {
vaVars.selectedCategory='';
LiveAgent_selectedCategory = vaInputs.select_topic_related_to_your_problem.getValue();
})()
then in second topic I tried like this:
 
var sysPropertyValue = gs.getProperty('x_4dai_va.connected_content_id');
 var sysPropertyObject = JSON.parse(sysPropertyValue);
 var topicSysId = sysPropertyObject[vaContext.LiveAgent_selectedCategory];
var options = [];
gs.info("line15"+topicSysId);
var grObj = new GlideRecordSecure("m2m_connected_content");
grObj.addEncodedQuery(''catalog_item!=NULL^topic.parent_topic=' + topicSysId + '^catalog_item.active=true'');
//gr.setLimit(5);
grObj.query();
while (grObj.next()) {
options.push({ 'value': grObj.getUniqueValue(), 'label': grObj.getDisplayValue('catalog_item') });
}
return options;
 
But it's not working. Can you suggest anything what I am missing here.
Thanks

"It's not working". So what's not working? I do assume the same not defined message on:

 

LiveAgent_selectedCategory = vaInputs.select_topic_related_to_your_problem.getValue();

 

Basically, because indeed, you did not define this. Same mistake as in your previous post.

@Mark Roethof Didn't get you, can you please elaborate please