Remove selected value from list collector based on selected value in current list collector

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2023 09:29 PM
I have a list collector that should only allow either "Dual Monitor" or "Single Monitor" to be selected, but never both. This list collector has other values that can be selected that should not be removed when removing "Dual Monitor" or "Single Monitor".
Example:
I add Dual Monitor to list collector and then add Single Monitor to list collector. Script should remove Dual Monitor and keep Single Monitor.
OR
I add Single Monitor to list collector and then add Dual Monitor to list collector. Script should remove Single Monitor and keep Dual Monitor.
In both examples, if other values are part of the list collector then they should remain

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 12:59 AM
Hi @Edwin Fuller ,
Try below client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ulist2 = newValue;
var newList = [];
if (ulist2.indexOf("sys-id-of-sm-device") > -1 && ulist2.indexOf("sys-id-of-dm-device") > -1) {
newList = ulist2.split(',');
var indexOfDM = newList.indexOf("sys-id-of-dm-device");
var indexOfSM = newList.indexOf("sys-id-of-sm-device");
if (indexOfDM > indexOfSM) {
var newList1 = newList.splice(indexOfSM, 1);
g_form.setValue("users_list", newList);
} else {
var newList2 = newList.splice(indexOfDM, 1);
g_form.setValue("users_list", newList);
}
}
}
Let me know how it goes.
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 07:20 AM
@Aman Kumar S I used this approach for a similar ask and it worked successfully thank you!
Small note for anyone using in the future - this won't work if you want to use it through Virtual Agent - as g_form.getControl isnt supported.