Issue with "Dynamic choice" in Virtual agent

bondita1
Tera Contributor

I want to create a 'Dynamic Choice' in the Virtual Agent to display a list based on the values in the Category field.
To achieve this, I have queried the sys_choice table with the following conditions.

bondita1_0-1716148812076.png

 

So that I should get the below option for Category.

bondita1_1-1716148854636.png

 

I have added the below code snippet in my script: 

(function execute() {
var options = [];
var gr = new GlideRecordSecure('sys_choice');
gr.addEncodedQuery('inactive=false^table=incident^element=category');
gr.setLimit(5);
gr.query();
while(gr.next()) {
options.push({ 'value': gr.getUniqueValue(), 'label': gr.getValue('label') });
}
return options;
})()

bondita1_3-1716149096201.png

 

But in my Virtual Agent, I am seeing other options that are not based on the query I provided.

Could someone please help me with this.

Thanks.

2 REPLIES 2

goldenjc97
Tera Contributor

@bondita1 - Were you able to figure this out?

GlideJ
Tera Contributor

For anyone else having this issue, it has to do with the filter on the query. Instead of 'table = incident' it should instead be 'name = incident'.

EX:

(function execute() {

var options = [];
var gr = new GlideRecord('sys_choice');

gr.addQuery('inactive', 'false');
gr.addQuery('name', 'incident');
gr.addQuery('element','category');
gr.query();

while(gr.next()) {
options.push({ 'value': gr.getUniqueValue(), 'label': gr.getValue('label') });
}
return options;

})()