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

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

"then technical issue is coming"

 

Usually when this happens, very useful information is written to the logs. What is the logs providing you? Please share.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

@Mark Roethof 

This I am getting in Logs:
11:26:09.492 Evaluator: com.glide.script.RhinoEcmaError: "selectedCategory" is not defined. Task.77d03cae1beb7d10134bddf59b4bcb14 : Line(13) column(0) 10: */ 11: var sysPropertyValue = gs.getProperty('x_4dai_va.connected_content_id'); 12: var sysPropertyObject = JSON.parse(sysPropertyValue); ==> 13: var topicSysId = sysPropertyObject[selectedCategory]; 14: var options = []; 15: gs.info("line15"+topicSysId); 16: var grObj = new GlideRecordSecure("m2m_connected_content");

But the strange thing is Just before this node I am using a text response where I am printing the value of selectedCategory, it is giving me correct value.

If I just look at the code that you shared, indeed selectedCategory is not defined. So please do so, or share where you did this. Just looking at what you shared, again you did not define it.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

@Mark Roethof 
In one topic I have defined it like this:

(function execute() {
vaVars.selectedCategory=' ';
selectedCategory = vaInputs.select_topic_related_to_your_problem.toString();
gs.info("line4:"+selectedCategory);
})()
After this I am using this variable in my topic directly. If this is not the way, can u please guide how i can achieve this