- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2020 07:45 AM
I've read many of the posts on how to remove selections from the right bucket of a list collector when a variables changes and can get it to work.
what i can't seem to get is how to populate the right bucket when a variable changes.
this is compounded further should the variable change again prior to submitting the form.
What i have is a list of Positions. Next there is a Matrix table of Apps to Position.
On my form i have a Position Select box, this update the Reference Qual of the List collector to show only those apps to need for the position. My users would like that "List" to automatically populate the right side of the list collector.
e.g. User selects Value 1 - List collector filters on this value and populates the right bucket automatically
Now user selects Value 2 - list collector clears right bucket, requeires, then auto populates right with new values.
I'm not sure that this is the best action and would be open for another idea on how to show required programs for a given position
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2020 05:43 AM
Very Very helpful and thank you for the "time out" explanation. I was wondering if that was the issue, based on observations, and was thinking for putting a timed Loop wait condition in the code.
I'm going to try this now. Thanks a lot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2020 01:05 AM
Hi Eric,
So are you saying you need this to happen on Variable 1 change
1) auto-populate values in right side of slush bucket -> this is handled in blog
2) apply filter and show required values in left slush bucket?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2020 09:36 AM
did you changed the variable name?
var myListCollector = g_list.get("yourvariable");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2020 04:54 AM
Some approaches can over complicate this. The key to populating the right bucket is to first make sure the options appear in the left bucket within the number (default is 100) of returned results - without filtering or searching - so they have to appear within the first (100) results of the query. For this reason, I always update the query prior to moving from left to right. If you only have a reference qualifier on the Apps list collector, you're probably noticing that the list doesn't re-load/re-query when Position changes, until you type a search character or filter the Apps. In addition to the reference qualifier, you'll want an onChange catalog client script with these lines
var varname = 'v_apps'; //replace with your list collector variable name
var filterstring = 'position=' + newValue; //replace with your working reference qualifier, or answer/response if returning from script include
window[varname + 'g_filter'].reset();
window[varname + 'g_filter'].setQuery(filterstring);
window[varname + 'acRequest'](null);
If your reference qualifier is more complex and requires calling a script include, filterstring can use the same answer since the easiest way to get both to work is to return a string in the format 'sys_idIN1...,2...,3...'. Now it's just a matter of moving everything from the left to the right. This is wrapped in a timeout to allow the filter reset to complete first, which could take a few seconds, so adjust the integer (3000 ms) accordingly
window.setTimeout(function(){
var leftBucket = gel(varName + '_select_0');
var rightBucket = gel(varName + '_select_1');
var selectedOptions = leftBucket.options;
var selectedIDs = new Array();
var index = 0;
for(var i = 0; i < selectedOptions.length; i++){
selectedIDs[index] = i;
index++;
}
rightBucket.options.length = '0';
moveSelectedOptions(selectedIDs, leftBucket, rightBucket);
sortSelect(rightBucket);
g_form.setReadOnly(varname, true); //if you don't want to allow the users to remove, or re-filter and add any selections without first selecting a different Position
}, 3000);
The rightBucket.options.length=0 should clear any selections before copying the new ones when Position changes again. If it doesn't you can add another block from var leftBucket (with different var names) down to and including the for loop, then
moveSelectedOptions(selectedIDs, rightBucket, leftBucket, '--None--');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2020 05:43 AM
Very Very helpful and thank you for the "time out" explanation. I was wondering if that was the issue, based on observations, and was thinking for putting a timed Loop wait condition in the code.
I'm going to try this now. Thanks a lot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2020 06:08 AM
Thank You again for the insight - It's working as desired.