Set value for List Collector
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2014 06:20 AM
Hi all
I did write a script which shall do something like "setValue('collectorName', valueArray);" for List Collectors. There is already a script available @ http://www.servicenowguru.com/scripting/client-scripts-scripting/move-list-collector-options/. That script does not work if the selected values are not part of the initial loaded list - this happens if you point the List Collector to a table with many records (> 100 by default).
So far I do have got the following code to load a bunch of users to the right side of the List Collector:
function setSysUserCollectorValues(collectorName, selectedOptionsArray) {
var documentFragment = document.createDocumentFragment();
for (var i = 0; i < selectedOptionsArray.length; i++) {
var gr = new GlideRecord('sys_user');
if (gr.get(selectedOptionsArray[i])) {
var option = document.createElement("option");
option.text = gr.user_name;
option.value = selectedOptionsArray[i];
documentFragment.appendChild(option);
}
}
var rightBucket = document.getElementById(collectorName + '_select_1');
rightBucket.options.length = 0;
rightBucket.appendChild(documentFragment);
eval(collectorName + 'acRequest(null)');
}
This is the script I use to reset the List Collector:
function resetCollectorValues(collectorName) {
var leftBucket = document.getElementById(collectorName + '_select_0');
leftBucket.options.length = 0;
var rightBucket = document.getElementById(collectorName + '_select_1');
rightBucket.options.length = 0;
}
- Is there a more elegant way to solve this? I would like to get rid of the fixed glide record to the sys_user table and the eval() function.
- It looks like the "no_filter" attribute does not work anymore with my code above. Why does it show the filter again after applying these scripts?
- Is there an out of the box feature to perform this operation?
Regards
-Luca.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2017 03:46 PM
So I tested this in a Jakarta Dev instance, and it works, with a catch. If you read the KB article closely you'll see that you have to set the control to work as a Glide List and not as a Slush Bucket.
In my testing, using g_form.setValue('u_user', 'some sys_id') worked as expected and populated the Glide List (note: the KB article shows to use u_user.setValue(), which is incorrect when doing this client-side). It did not work when the control was set as a Slush Bucket.
So, if you're UI requires the Slush Bucket, you're still out of luck 😞
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2018 05:11 PM
Hi Michael,
I am trying to copy RITM and have few list collector variables.Values are being copied but getting error" Unhandled exception in GlideAjax".
Have tried steps mentioned in KB article ServiceNow KB: Unable to set the value of a list collector using setValue() (KB0622779)
but still no luck.Also used try & catch method.
Any suggesstion?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 05:25 AM
An error involving GlideAjax implies you're doing more in your client script than just the call to g_form.setValue()? Without seeing any code, it's near impossible to tell. Try commenting out all code except the g_form.setValue() and see if that works. If it does, start introducing more of your other code to isolate the issue.
Michael
