Client Catalog script to move list collector options to selected in slushbucket onLoad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 02:50 PM
Hi There,
I have a List Collector variable on a catalog item called "Role" which references the "question_choice" table. After filtering it has four available options. Role 1, Role 2, Role 3, and Role 4. I need a client catalog script that when the form loads, if the value of a "Role_preset" variable is set to "Software Developer, i want the script to add Role 1 and Role 2 to the right side of the slushbucket.
I have tried a whole bunch of things but cant for the life of me get a script to move items from the left to the right. Any help would be much appreciated. I have something similar working for multiple choice variables but not list collectors. Below is currently what im trying.
function onLoad() {
// Get the value of the "role_preset" variable
var rolePresetValue = g_form.getValue('variables.role_preset');
// Preselect options in the "Role" list collector variable based on the "role_preset" value
if (rolePresetValue === 'Software Developer') {
// Use pipe-separated values for the options to preselect
g_form.setValue('Role', '86f1c2aa1ba729100ee7eac2604bcb94|4542ce6a1ba729100ee7eac2604bcba0');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 10:37 PM
are you setting default value for that Role_preset variable?
try this
also ensure you are comparing correct values
function onLoad() {
// Get the value of the "role_preset" variable
var rolePresetValue = g_form.getValue('role_preset');
alert(rolePresetValue);
// Preselect options in the "Role" list collector variable based on the "role_preset" value
if (rolePresetValue === 'Software Developer') {
// Use pipe-separated values for the options to preselect
g_form.setValue('role', '86f1c2aa1ba729100ee7eac2604bcb94,4542ce6a1ba729100ee7eac2604bcba0'); // use correct role variable name here
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 06:14 AM
What i am trying to do is if the role_preset variable is set to "Software Developer", for two of the available roles to be moved to the right side of the slushbucket.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 07:48 AM
if you want this to happen on form load then you can use default value in that variable
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 07:58 AM
Can i make the default value conditional? What is happening is this is an access request to an application. Most of the time people will request access to this app specifically, in those cases the "role_preset" variable will be empty and users will just select what they want. But if the "role_preset" is used, we want to pre-populate the choices based on their selection.