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 03:10 AM - edited 02-18-2025 03:11 AM
Hi,
You can write a simple script and just copy the data form excel(as Array) to insert them all.
For Manual entry Insert & Stay would be most optimum.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 03:27 AM
Thanks @Anurag Tripathi for response.
Can you please give more details on #1 You can write a simple script and just copy the data form excel(as Array) to insert them all.
Ujjwal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 03:33 AM - edited 02-18-2025 03:34 AM
Something like this, You can run this in a background script.
I haven't tested it so may need some tweak.
var choice_List= ['one', 'two', 'three'];
var field = '<sys_id of variable>';
for (var i = 0; i < choice_List.length; i++) {
insertRecord(choice_List[i], 'en', choice_List[i], i)
}
function insertRecord(name,field, lang, value, order) {
var grChoice2 = new GlideRecord("sys_choice");
grChoice2.initialize();
grChoice2.setValue('name', name);
grChoice2.setValue('element', field);
grChoice2.setValue('language', lang);
grChoice2.setValue('value', value);
grChoice2.setValue('order', i*100);
grChoice2.insert();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 03:30 AM
not a good practice to have 100 drop down. not a good user experience.
Why not create a custom table with name field and load data into that.
Then have a reference variable pointing to that table
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