adding multiple question choices for select box
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 03:06 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 05:10 AM - edited 02-18-2025 05:16 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 05:17 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 05:23 AM - edited 02-18-2025 05:26 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 05:27 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 03:36 AM
Hi @Ujjwal1
You mean 100 dropdown values? No, that’s not recommended. As per best practices:
- A choice field should have 8–10 values.
- 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.
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]
****************************************************************************************************************