Dynamic choice input is not returning value

pandeyved
Tera Contributor

Hi All,
I am facing issue with one thing. In Virtual Agent I am using Dynamic Choice Input. Where I am writing this code to print choices, so Choices are printing successfully, but when the user is selecting any choices from it, then technical issue is coming.

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

one more thing, at the place of topicSysId if we give any hardcoded sysid it is working fine.
In logs I checked selectedCategory is showing as undefined but it is defined in some other topics where I am giving values to selectedCategory, so why I will define here.

Kindly Guide
Thanks
9 REPLIES 9

Yes but have you defined selectedCategory within the step your question is about? If I look at the code: no you did not.

 

For example, perhaps:

var topicSysId = sysPropertyObject[selectedCategory];

 

Should be:

var topicSysId = sysPropertyObject[vaVars.selectedCategory];

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

@Mark Roethof 
Thanks, but I tried this way also, but it is not giving me output. Though it is not giving errors but not giving proper output also.
Lets say in first topic value of selectedCategory is Hardware, so ideally in second topic also it should come as Hardare, but if I am using vaVars.selectedCategory, then empty is coming.
Anything I am missing?
Thanks for help

Are you passing the value to the other topic? (I thought this was about steps within a topic, my bad)

 

Just using the same vaVars over different topics does not work.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

@Mark Roethof 
Then can yo please help what I can do?

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

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn