Duplicate Value in Dynamic Choice List
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2024 01:37 AM
Hi all,
May I need your help to remove duplicate value in Dynamic Choice options
Below my script:
var options = []; // add options here...
var gr = new GlideRecord('sn_hr_core_mgm_quota_management_seat_table');
gr.addQuery('u_filled_unfilled', 'Unfilled');
gr.orderBy('u_quota_usage_deadline');
gr.query();
while(gr.next()){
options.push({ 'value': gr.getValue('u_quota_position_chn'), 'label': gr.getValue('u_quota_position_chn')});
}
return options;
Below result:
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2024 06:51 AM - edited 06-06-2024 06:56 AM
You can check the array to see if the value already exists. If it doesn't, push it to the array, otherwise don't push it. This link should help you
Your code would looks something like this
var options = []; // add options here...
var gr = new GlideRecord('sn_hr_core_mgm_quota_management_seat_table');
gr.addQuery('u_filled_unfilled', 'Unfilled');
gr.orderBy('u_quota_usage_deadline');
gr.query();
while(gr.next()){
if(options.indexOf(gr.getValue('u_quota_position_chn') == -1) {
options.push({ 'value': gr.getValue('u_quota_position_chn'), 'label': gr.getValue('u_quota_position_chn')});
}
}
return options;