Select Options - Auto-Populated when there is only 1 option available
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 10:45 AM - edited 06-19-2025 11:57 AM
Hi everyone, how are you?!
I need the field to be auto-populated when there is only 1 option in the Select Box (img_1)
I am using this code in the 'Catalog Client Script', but it is not working. (img_2)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var custReq = g_form.getElement('subservice');
if (custReq.options.length == 1) {
g_form.setValue('subservice', custReq.options[0].value);
}
}
Note that this message appears regarding the use of DOM, but I have already set it to "isolate script -img_0", but it still doesn't work (img_3)
I also replaced getElement() with getValue() or getControl(), but without success! (This replacement is a suggestion from SN itself)
Note: I used this suggestion as a reference: "https://www.servicenow.com/community/csm-forum/how-to-autopopulate-choice-if-there-is-single-value/m... but it is not working as well.
I have already created BR:
if (current.subservice.nil()) {
var gr = new GlideRecord('sys_choice');
gr.addQuery('conditions', 'value');
gr.query();
if (gr.getRowCount() == 1 && gr.next()) {
current.subservice = gr.sys_id;
}
}
Does anyone have any suggestions?
Thanks.
Note: When there is only 1 option available, it doesn't make sense for the user to have to select it, because it should be filled in
There is a similar question in this Community link.
I used this same code to test, but as mentioned above, but unfortunately it didn't work.
Does anyone have any suggestions?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 11:19 AM - edited 06-19-2025 11:49 AM
.