- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2023 08:51 AM
On a form I'm using a list collector that has "All" as the default value.
How can I clear "All" as soon as any other selection is made?
I was trying to use an onchange catalog client script to remove the option but this isn't working:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == 'Alaska') {
g_form.removeOption('work_state', 'all', '- All -');
}
}
Any suggestions?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2023 04:39 AM
Hi Stermieri,
Try this:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var defaultValue = "<sys_id of the default value>";
var arrList = g_form.getValue('work_state').split(",");
//Is 'All' is in list, get its' index....
var all_index = -1;
for (i = 0; i < arrList.length; i++) {
if (arrList[i] == defaultValue) {
all_index = i;
}
}
if (all_index > -1) {
//if 'All' was the default value (and there is more than 1 item in field), remove 'All'
if (all_index == 0 && arrList.length > 1) {
arrList.splice(all_index, 1);
g_form.setValue('work_state', arrList.join(","));
} else {
//If 'All' added later, remove everything else
g_form.setValue('work_state', defaultValue);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2023 04:39 AM
Hi Stermieri,
Try this:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var defaultValue = "<sys_id of the default value>";
var arrList = g_form.getValue('work_state').split(",");
//Is 'All' is in list, get its' index....
var all_index = -1;
for (i = 0; i < arrList.length; i++) {
if (arrList[i] == defaultValue) {
all_index = i;
}
}
if (all_index > -1) {
//if 'All' was the default value (and there is more than 1 item in field), remove 'All'
if (all_index == 0 && arrList.length > 1) {
arrList.splice(all_index, 1);
g_form.setValue('work_state', arrList.join(","));
} else {
//If 'All' added later, remove everything else
g_form.setValue('work_state', defaultValue);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2023 07:38 AM
Hi Craig,
I have a similar requirement where I have to remove email ids from Users field on Scheduled Reports table which does not belong to particular regex (/^[a-zA-Z0-9._-]+@(example)\.com$/), like if user is trying to add (abc@abc.com) it should get removed from the list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2023 11:22 AM
Thank you Craig,
That works beautifully