Duplicate Value in Dynamic Choice List

Jeff42
Tera Contributor

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:

Screenshot 2024-06-06 163704.png

 

Thank you

 

1 REPLY 1

Zach Koch
Giga Sage
Giga Sage

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 

Check array for value 

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;

 

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!