adding multiple question choices for select box

Ujjwal1
Tera Contributor

hi,

I need to add multiple choices (more than 100 items) for select box(variable).

Please suggest, if there is any fast track method to add multiple choices  in select box( other than "insert and stay").

 

Thanks

Ujjwal

11 REPLIES 11

hi @Ankur Bawiskar 

your suggestion is absolutely  correct. But business wants this choices as dropdown.

 

Even select box has search option. So it do not break layout of form.

Choice list for Select box.png

@Ujjwal1 

then load data to question_choice table with the correct column

OR

you can use background script

Note: Remember this needs to be captured as well since it will be migrated to next instance

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

yes @Ankur Bawiskar 

that is plan , to add choice in question_choice

 

var choice_listname =[];
var choice_Listvalue=[]; // item should be same as of name

var field = '<sys_id of variable>';
for (var i = 0; i < choice_listname.length; i++) {
    insertRecord(choice_listname[i], field, choice_Listvalue[i], i);
}

function insertRecord(name, field, value, order) {
    var grChoice = new GlideRecord("question_choice");
    grChoice.initialize();
    grChoice.setValue('text', name);
    grChoice.setValue('question', field);
    grChoice.setValue('value', value);
    grChoice.setValue('order', i * 100);

    grChoice.insert();
}

 

@Ujjwal1 

try this and ensure you select correct update set and all those choices will get captured in your current update set

var choice_listname = [];
var choice_Listvalue = []; // item should be same as of name

var field = '<sys_id of variable>';
for (var i = 0; i < choice_listname.length; i++) {
    insertRecord(choice_listname[i], field, choice_Listvalue[i], i);
}

function insertRecord(name, field, value, order) {
    var grChoice = new GlideRecord("question_choice");
    grChoice.initialize();
    grChoice.setValue('text', name);
    grChoice.setValue('question', field);
    grChoice.setValue('value', value);
    grChoice.setValue('order', i * 100);

    grChoice2.insert();

    var gum = new GlideUpdateManager2();
    gum.saveRecord(grChoice2);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Ujjwal1 

You mean 100 dropdown values? No, that’s not recommended. As per best practices:

  1. A choice field should have 8–10 values.
  2. Subcategories should have a maximum of 2 levels with 8–10 values each.

Adding 100 values will significantly impact the user experience negatively.

Instead, use a reference field. Create a new table to store these values and use it as a reference. This approach is more efficient and user-friendly.

 

https://www.servicenow.com/community/developer-forum/what-is-the-best-way-to-hide-100-s-of-choices-i...

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************