- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2025 01:43 AM
I'm trying to set variable values for a Select Box variable. However, the choices are added via a catalog client script. How can I select a value for this variable and proceed with the submission if the choice does not appear in this step?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2025 04:55 AM
you must have created choices in question_choice table for that variable?
If not then it won't come in your Step when you set the variable value.
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
06-27-2025 04:04 AM
Hello @symonflores_23,
g_form.setValue()
within an onSubmit
catalog client script. First, ensure the script has access to the intended value, and then use the script to set the variable's value before submission. If the choice needs to be dynamically added to the select box, you can manipulate the question_choice
table within a client script; however, this is generally discouraged and may require adjustments to read ACLs.
- You have a Select Box variable on a catalog item.
- The choices for this variable are being added dynamically via a Catalog Client Script.
- You want to pre-select a specific value in this Select Box, even if that value isn't currently present in the options.
- You also need to ensure the form submission proceeds, even if the desired value isn't initially available in the dropdown.
g_form.setValue()
:- Identify the variable: Make sure you have the correct name of the Select Box variable you want to manipulate.
- Locate the value: You'll need to know the exact value (not just the display value) that you want to pre-select.
- Create an
onSubmit
Catalog Client Script: This script will run before the form is submitted. - Use
g_form.setValue()
: Inside the script, useg_form.setValue('your_variable_name', 'your_value');
to set the desired value. If the value is a string, make sure it is enclosed in single quotes. - Example:
function onSubmit() {
g_form.setValue('your_variable_name', 'desired_value');
return true; // Allow submission
}
- Return
true
: Ensure the script returnstrue
to allow the form to submit.
-
Adding choices to the
question_choice
table:If the intended value is not always present, you might consider dynamically adding it to thequestion_choice
table via a client script. However, this is generally not recommended. -
ACLs:Adding or modifying choices in the
question_choice
table may require adjustments to read access control lists (ACLs) to ensure the script has the necessary permissions. This can impact other parts of the system. -
Alternatives:If you frequently need this functionality, consider using a Reference qualifier or a Reference variable instead of dynamically adding choices to the
question_choice
table. These options provide better control and maintainability.
os_version
and you want to pre-select "Windows 10" in it.- Find the value: You need to know the actual value associated with "Windows 10" in the
question_choice
table. Let's assume it'swindows_10
. - Create the script:
function onSubmit() {
g_form.setValue('os_version', 'windows_10');
return true;
}
g_form.setValue()
in an onSubmit
Catalog Client Script to select a specific value for your Select Box variable, even if the choice isn't initially available. If you need to dynamically add choices, explore alternative options like Reference qualifiers or Reference variables for better system management. - Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2025 04:56 AM
Seems you got confused on the question asked.
It's about ATF and not about scripting.
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-27-2025 04:55 AM
you must have created choices in question_choice table for that variable?
If not then it won't come in your Step when you set the variable value.
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
06-28-2025 06:38 AM
Hope you are doing good.
Did my reply answer your question?
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