- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2020 01:50 PM
Hi,
I have a list collector in a catalog item and there's a onchange client script on it. The values are populated correctly in catalog item view. But the selected values (right slushbucket) are empty after the submission in RITM view. I have checked both applies on a catalog item view and applies on requested item view. I have attached a screenshot for your reference. Please assist.
Below is the script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var req = g_form.getValue('u_request_type2');
if(req== '400' || req== '500' || req== '600')
{
var ga = new GlideAjax('getOraData');
ga.addParam('sysparm_name', 'getdata');
ga.addParam('sysparm_appID',g_form.getValue('app_name').toString());
ga.getXML(ajaxResponse);
}
function ajaxResponse(serverResponse){
var answer = serverResponse.responseXML.documentElement.getAttribute("answer");
var checkans = answer.split("||")[1].trim();
if(checkans == ''){
alert('Please select correct application name as this does not have related database');
}
else{
var arr = answer.split('||');
if(window == null){
g_form.setValue('u_database_name2', arr[1], arr[0]);
}
else
addItemstoList('u_database_name2', arr[1], arr[0]);
}
function addItemstoList(listcollector, sysid, display_value){
var varName = listcollector;
var leftBucket = g_form.getElement(varName + '_select_0');
var rightBucket = g_form.getElement(varName + '_select_1');
var selectedOptionsIDs = [];
leftBucket.options.length = 0;
if(sysid !=''){
var myCIArray = sysid.split(',');
var displayvalue = display_value.split(',');
for(i=0; i < myCIArray.length; i++){
var option = document.createElement('option');
option.value = myCIArray[i];
option.text = displayvalue[i];
leftBucket.add(option);
}
}
sortSelect(rightBucket);
moveSelectedOptions(selectedOptionsIDs, leftBucket, rightBucket, '--None--');
}
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2020 03:21 AM
That confirms my concern that the choices from the left side are not actually getting populated on the right - that's why it appears empty after submit, unless you select something manually. Looking over your script, I don't see how anything is being selected / moved to the right bucket. You're declaring an empty array selectedOptionsIDs, then building the Available selections in the left bucket, then calling moveSelectedOptions, but selectedOptionsIDs is still empty. If your left bucket is getting populated correctly when the app name is selected, then you can use this to move every value from the left to the right - after your addItemstoList function, before the moveSelectedOptions call
var selectedOptions = leftBucket.options;
var index = 0;
for(var i = 0; i < selectedOptions.length; i++){
selectedOptionsIDs[index] = i;
index++;
}
For what it's worth, it seems like you're doing a bit more coding than necessary. If your u_database_name2 list collector is referencing the same table as the GlideRecord query in your Script Include is using, then you can push each sys_id of the matching records to an array, then
return 'sys_idIN' + arr.join(',')
Here's what I've used on the client side to reset the filter and select all results. It may take a second to load the filter, so it's wrapped in a timeout to ensure loading is finished before it tries to select everything. This would replace the contents of your addItemstoList function, with one less parameter needed. The display value of the list collector options are whatever field is defined on the referenced table with the Display box checked/true.
var varName = 'members';
var filterString = answer;
window[varName + 'g_filter'].setQuery(filterString);
window[varName + 'acRequest'](null);
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);
}, 3000);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2020 02:06 PM
This script is running on change of a variable other than the list collector, correct? I would uncheck Applies on Requested Items to see if that makes a difference. Also, try manually selecting one value after the auto-population in the catalog item view to see if that one sticks. Is the Available side on the RITM the same as when the request form loads - looks like a bunch of entries without a display value at the beginning of the list?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2020 02:48 PM
Hi Brad,
Unchecked Applies on Requested Items, there's no difference.
Yes, the script runs on change of another variable (app name). In the catalog view, i can move values from left to right and even the workflow is picking up the value I have selected in the list collector. But don't see the selected values in RITM view.
And yes, when the request form loads, the available side is empty and based on the app name selected, the available side of list collector will be populated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2020 03:21 AM
That confirms my concern that the choices from the left side are not actually getting populated on the right - that's why it appears empty after submit, unless you select something manually. Looking over your script, I don't see how anything is being selected / moved to the right bucket. You're declaring an empty array selectedOptionsIDs, then building the Available selections in the left bucket, then calling moveSelectedOptions, but selectedOptionsIDs is still empty. If your left bucket is getting populated correctly when the app name is selected, then you can use this to move every value from the left to the right - after your addItemstoList function, before the moveSelectedOptions call
var selectedOptions = leftBucket.options;
var index = 0;
for(var i = 0; i < selectedOptions.length; i++){
selectedOptionsIDs[index] = i;
index++;
}
For what it's worth, it seems like you're doing a bit more coding than necessary. If your u_database_name2 list collector is referencing the same table as the GlideRecord query in your Script Include is using, then you can push each sys_id of the matching records to an array, then
return 'sys_idIN' + arr.join(',')
Here's what I've used on the client side to reset the filter and select all results. It may take a second to load the filter, so it's wrapped in a timeout to ensure loading is finished before it tries to select everything. This would replace the contents of your addItemstoList function, with one less parameter needed. The display value of the list collector options are whatever field is defined on the referenced table with the Display box checked/true.
var varName = 'members';
var filterString = answer;
window[varName + 'g_filter'].setQuery(filterString);
window[varName + 'acRequest'](null);
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);
}, 3000);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2020 06:08 AM
Thank you Brad