Issue in selecting the output from dynamic choices

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
7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@pandeyved 

from that property you are parsing and then using the value

the issue is because of the variable selectedCategory

is your script depending on some previous input which user gave or you simply want to get value from system property?

what does that property hold? share screenshot.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi @Ankur Bawiskar 
Thanks for the reply.
My Scripts depends on the previous value which is already stored in the variable selectedCategory.
In selectedCategory I will get the input from user let's say ""Hardware" which is defined in other topic through which this topic is linked.
And then I am using this value to check that it is present in system property and if yes then I am fetching the corresponding value. This is the screenshot of property:

pandeyved_0-1704699023913.png

 

Thanks

@pandeyved 

so that variable should store the value so that your script runs fine.

ensure you have access to this variable from other topic.

Please check how you can share data between topics in VA

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar 

Can you help in it, because I have defined it in previous topic as vaVars. And if I am printing it's value also then it is printing correctly.