Auto-Populate List Collector Variable Based on Select Box Value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2023 07:42 AM - edited ‎08-09-2023 07:46 AM
Hello, I have a Select Box variable called Type of Network Account (u_type_of_network_account) with 2 choices - "Network Logon Only" and "Network Logon with Email". Based on the which option the user picks, I want to auto-populate a selection in a List Collector variable called Systems Access (u_systems_access). The options that I want to select in the List Collector are "Network Login Only (No Email)" or "Network Sign On and Outlook E-mail", depending on what the user selects on the Type of Network Account question. I created an onChange Catalog Client Script and have a general direction on what to do, but I'm not sure how to select the option that I want from the array and push it to the "Selected" side of the Systems Access list collector box.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
if(newValue == 'Network Logon Only') {
//g_form.setValue('u_systems_access', 'Network Login Only (No Email)');
//g_form.setValue('u_systems_access', 'Network Sign On and Outlook E-mail');
//}
//Name of variable to move options from
var varName = 'u_systems_access';
var leftBucket = gel(varName + '_select_0');
var rightBucket = gel(varName + '_select_1');
var selectedOptions = leftBucket.options;
//Get an array of all option IDs to move
var selectedIDs = new Array();
var index = 0;
for(var i = 0; i < selectedOptions.length; i++){
selectedIDs[index] = i;
index++;
}
//Move all returned options from right to left bucket and sort the results
//Switch 'rightBucket' and 'leftBucket' to move from left to right
moveSelectedOptions(selectedIDs, leftBucket, rightBucket, '--None--');
//Sort the resultant options in the left bucket
sortSelect(rightBucket);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2023 08:04 AM
Hi @John Bone
List collector variable (u_syste_access) must be referencing to some table (check in type specification).
Now when you have list collector referencing to table then from script it will be expecting a sys_id of records from its referenced table. The thing you are trying is you are setting value from other variable.
Can you share screenshot of the both variables ? and do you have "Network Logon Only" and "Network Logon with Email" records on referenced table of list collector variable?
Regards,Sushant Malsure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2023 08:40 AM
Hello @sushantmalsure!
The Systems Access (u_systems_access) List Collector variable is a reference variable to a table called User Profile Change Request Systems (u_upcr_systems). Yes, the "Network Logon Only" and "Network Logon with Email" are records on the User Profile Change Request Systems (u_upcr_systems) table.
Here are screenshots of the Type of Network Account (u_type_of_network_account) and Systems Access (u_systems_access) List Collector variables:
Thank you very much!
John Bone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2023 09:16 AM - edited ‎08-09-2023 09:18 AM
ok. Then everything looks clear now.
The issue is you are trying to set value of list collector which is expecting a sys_id and not the selectted value in other variable.
Now to get the sys_id of those record from table, you need to query on table u_upcr_systems, and to query from client script you need to use GlideAjax which should a call a script include .
Once you have sys_ids of those records which you are trying to set, you can set value of list collector variable with ',' seperated items and that will be all 🙂
eg:
g_form.setValue('list_collector_variable', '1,2,3,4,5'); // comma separated sys_id's of records.
Regards,Sushant Malsure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2023 07:07 AM
@John Bone ..
Regards,Sushant Malsure