- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2017 08:23 AM
I have a Catalog Item with a Yes/No Field
If Yes is selected
The UI policy will show a List collector, allowing them to select more than one role. This references a custom table I created to store the values of the roles.
If the customer changes the question from Yes to No
The List collector does not clear the selected entries.
The script I am using is not working and I wondered if someone can give me some assistance?
Steps to Reproduce
- Selected Related list > Catalog Client Scrips from the Catalog item form
- Selected onChange
- Selected Field sap_access_to_coe_ams { this is the Yes/No question}
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var sapAccessToCoe = g_form.getValue('sap_access_to_coe_ams'); //Create variable and get the current value
if (sapAccessToCoe == 'No '); { //if If no has been selected for Sap access to Coe
g_form.setValue('sap_role_coe'); //This is the List collector field. To set Value to null
}
}
When I save this and then try the form the values are still showing and not clearing as I would expect it to.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2017 08:30 AM
ServiceNow support have got back to me with a working script. If anyone is trying to do the same thing. this might help.
if (isLoading || newValue == '') {
return;
}
var sapAccessToCoe = g_form.getValue('sap_access_to_coe_ams'); //Create a variable for the Yes No field
if (sapAccessToCoe == 'no'); { //If the yest No question for COE AMS is No
var listCollectorName = 'sap_role_coe'; //Name of your list collector
var leftBucket = gel(listCollectorName + '_select_0');
var rightBucket = gel(listCollectorName + '_select_1');
var selectedOptions = rightBucket.options;
var selectedIDs = [];
for(var i = 0; i < selectedOptions.length; i++){
//Check for the item to add here based on sys_id
selectedIDs.push(i);
//var value = selectedOptions[i].value;
//rightBucket.remove(value);
// var lefBucket = gel(listCollectorName + '_select_0');
//leftBucket.add(value);
}
moveSelectedOptions(selectedIDs,rightBucket,leftBucket,'--None--');
sortSelect(leftBucket);
var leftOptions = leftBucket.options;
for(var j = 0; j<leftOptions.length; j++){
var value = leftOptions[j].innerHTML;
if(value == '--None--'){
leftBucket.remove(j);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2017 08:33 AM
HI Sarah
Please find the below link it may help you
https://www.servicenowguru.com/scripting/client-scripts-scripting/move-list-collector-options/
Please provide your feedback appropriately (Like, Helpful, Endorse AND/OR Correct) to help community.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2017 08:35 AM
To clear List Collector values on change of a variable in SR.
Please provide your feedback appropriately (Like, Helpful, Endorse AND/OR Correct) to help community.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2017 08:37 AM
Similar Thread: To clear List Collector values on change of a variable in SR.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2017 02:11 AM
Thanks for this,
I have a working script now but have another problem. If you can help?
Is there a way to add to the script to refresh the Available options.
Steps to reproduce
Created client script as follows
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var sapAccessToCoe = g_form.getValue('sap_access_to_coe_ams'); //Create a variable for the Yes No field
if (sapAccessToCoe == 'no'); { //If the yest No question for COE AMS is No
var listCollectorName = 'sap_role_coe'; //Name of your list collector
var rightBucket = gel(listCollectorName + '_select_1');
var selectedOptions = rightBucket.options;
for(var i = 0; i < selectedOptions.length; i++){
//Check for the item to add here based on sys_id
var value = selectedOptions[i].value;
rightBucket.remove(value);
}
}
}
- Selected Try it
- Selected Yes to Would you like to Add/Remove Permissions for COE/AMS?
- The List collector appears (showing all options)
- Move items from Available to Selected
-
- Change the Question Would you like to Add/Remove Permissions for COE/AMS? To No
- Change the Question Would you like to Add/Remove Permissions for COE/AMS? To Yes
- The Available list has not refreshed to show all the items or clearing the selection properly. It still says Sap Access role needed at the bottom.
-