- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2025 03:13 AM - edited ‎08-13-2025 03:21 AM
Hi Community, good day!
I have a requirement where a catalog item variable was initially of type Select Box with choices a, b, c but I had to convert it to a List Collector using a certain technique.
https://www.servicenow.com/community/developer-forum/how-do-i-allow-multiple-selections-of-choices-o...
Now, the requirement is as follows:
When a user selects 1 option in the List Collector, a single-choice variable below should be pre-selected, and a Multi-line Select field with that name should appear.
Three multi-line select fields are already created, just need to build a functionality that could do so.
When the user selects 2 options, two such Multi-line Select fields should appear.
When the user selects 3 options, three Multi-line Select fields should appear, and so on matching the number of selections made in the List Collector.
Has anyone implemented something similar? Any guidance or script examples would be greatly appreciated.
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2025 05:41 AM - edited ‎08-13-2025 07:02 AM
Hi @DevYadav , Hope you're doing well.
you can try the below script, This script hides all three multiline text fields, checks which list collector options are selected by their sys_ids, and then shows only the corresponding fields based on the selection mapping.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) return;
var selectedValues = g_form.getValue('test_choices').split(',');
g_form.setVisible('u_1', false);
g_form.setVisible('u_2', false);
g_form.setVisible('u_3', false);
// Mapping: sys_id => field name
var mapping = {
"1f0f3b06c31322102a49b91ed401313c": "u_1", // Option 1
"331f3bc2c31322102a49b91ed40131d7": "u_2", // Option 2
"a22ff746c31322102a49b91ed4013184": "u_3" // Option 3
};
for (var i = 0; i < selectedValues.length; i++) {
var trimmedValue = selectedValues[i].trim();
if (mapping[trimmedValue]) {
g_form.setVisible(mapping[trimmedValue], true);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2025 05:41 AM - edited ‎08-13-2025 07:02 AM
Hi @DevYadav , Hope you're doing well.
you can try the below script, This script hides all three multiline text fields, checks which list collector options are selected by their sys_ids, and then shows only the corresponding fields based on the selection mapping.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) return;
var selectedValues = g_form.getValue('test_choices').split(',');
g_form.setVisible('u_1', false);
g_form.setVisible('u_2', false);
g_form.setVisible('u_3', false);
// Mapping: sys_id => field name
var mapping = {
"1f0f3b06c31322102a49b91ed401313c": "u_1", // Option 1
"331f3bc2c31322102a49b91ed40131d7": "u_2", // Option 2
"a22ff746c31322102a49b91ed4013184": "u_3" // Option 3
};
for (var i = 0; i < selectedValues.length; i++) {
var trimmedValue = selectedValues[i].trim();
if (mapping[trimmedValue]) {
g_form.setVisible(mapping[trimmedValue], true);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2025 06:30 AM
Thanks @IbrarA that is exactly what I need