- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 02:09 AM - edited 09-11-2024 04:09 AM
Hi Team
please advise if something is wrong with the below script
Thanks
Levino
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Adjust the condition and value to be removed as needed
var valueToRemove = 'specific_value_to_remove';
var listCollectorName = 'list_collector';
// Get the List Collector variable
var listCollector = g_form.getControl(listCollectorName);
if (listCollector) {
var options = listCollector.options;
for (var i = options.length - 1; i >= 0; i--) {
if (options[i].value === valueToRemove) {
listCollector.remove(i);
}
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 04:38 AM
The value of a List Collector is a comma-separated list of sys_ids of records on the List table, so make sure valueToRemove is a sys_id, not display name, etc. If you want to remove the value from the right / Selected box, one way to do it is to get the current value, split it into an array, find the position of the valueToRemove, splice the array to remove it, then populate the variable with what's left.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Adjust the condition and value to be removed as needed
var valueToRemove = 'specific_value_to_remove'; //sys_id of record on List referenced table
var listCollectorName = 'list_collector';
// Get the List Collector variable
var listCollector = g_form.getValue(listCollectorName);
if (listCollector) {
// Split List Collector values into an array
var listArr = listCollector.split(',');
// Find array position of valueToRemove
var index = listArr.indexOf(valueToRemove);
if (index !== -1) { //valueToRemove was found in array
listArr.splice(index, 1); //remove array member from this array
}
g_form.setValue(listCollectorName, listArr.join(','));
}
If you want to remove the specific value from the left / Available box you can change the filter in an onChange script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2024 04:38 AM
The value of a List Collector is a comma-separated list of sys_ids of records on the List table, so make sure valueToRemove is a sys_id, not display name, etc. If you want to remove the value from the right / Selected box, one way to do it is to get the current value, split it into an array, find the position of the valueToRemove, splice the array to remove it, then populate the variable with what's left.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Adjust the condition and value to be removed as needed
var valueToRemove = 'specific_value_to_remove'; //sys_id of record on List referenced table
var listCollectorName = 'list_collector';
// Get the List Collector variable
var listCollector = g_form.getValue(listCollectorName);
if (listCollector) {
// Split List Collector values into an array
var listArr = listCollector.split(',');
// Find array position of valueToRemove
var index = listArr.indexOf(valueToRemove);
if (index !== -1) { //valueToRemove was found in array
listArr.splice(index, 1); //remove array member from this array
}
g_form.setValue(listCollectorName, listArr.join(','));
}
If you want to remove the specific value from the left / Available box you can change the filter in an onChange script