- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 12:40 AM
Hi All,
In my catalog item I have a list collector, where one of the options is 'other'. I would like to show (and make mandatory) a string field 'other consumer' when this option is selected.
Currently I have a client script, but when I select 'other' the field 'other consumer' does not show:
Here is the condition:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 12:50 AM
Hi @dev_K
use following script, which is working fine:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Get the values from the list collector
var selectedValues = g_form.getValue('consumer_list');
// Check if 'Other' is selected
if (selectedValues.indexOf('Other') !== -1) {
// Show and make mandatory the 'other_consumer' field
g_form.setDisplay('other_consumer', true);
g_form.setMandatory('other_consumer', true);
} else {
// Hide and make not mandatory the 'other_consumer' field
g_form.setDisplay('other_consumer', false);
g_form.setMandatory('other_consumer', false);
}
}
If you want to check your script, please share here to verify.
I hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.
Thank you
rajesh.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 12:43 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 12:50 AM
Hi @dev_K
use following script, which is working fine:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Get the values from the list collector
var selectedValues = g_form.getValue('consumer_list');
// Check if 'Other' is selected
if (selectedValues.indexOf('Other') !== -1) {
// Show and make mandatory the 'other_consumer' field
g_form.setDisplay('other_consumer', true);
g_form.setMandatory('other_consumer', true);
} else {
// Hide and make not mandatory the 'other_consumer' field
g_form.setDisplay('other_consumer', false);
g_form.setMandatory('other_consumer', false);
}
}
If you want to check your script, please share here to verify.
I hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.
Thank you
rajesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 01:50 AM
Actually I used this script, and replaced the names of the variables but it is not working:
Is getValue() a right method of retrieving values from the list collector??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2024 02:20 AM
Hi @dev_K
Yes, getValue() is working fine with list collector, you can verify with following code:
// Get the sys_id string of selected items in the list collector
var selectedValues = g_form.getValue('list_collector_variable_name');
// Convert the comma-separated string into an array
var selectedArray = selectedValues.split(',');
// Example of how to iterate over the array
for (var i = 0; i < selectedArray.length; i++) {
console.log('Selected sys_id:', selectedArray[i]);
}
i hope this clarifies, if any issue facing let me know.
thank you