- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2025 05:44 AM
Hey guys!
I want to create an onchange client script for a catalog item based on selection in select box 'order_type', which has three choices: 'new_environment', 'change' and 'decommissioning'.
When 'new_environment' is selected in 'order_type' then we should hide the selection 'no_change' in select box 'node_size' and 'no_change' in select box 'node_amount'.
If you change 'order_type' to 'change' or 'decommissioning' then 'no_change' should be restored and visible.
So when:
I want to hide:
I just can't get it to work.
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2025 02:43 AM
Hello @ronro2
It doesn't works like that with choice type variables. You need to clear the options first.
Use this ➡️ g_form. clearOptions('<FIELD_NAME>');
Then if you want to add another option you need one by one add it.
GlideForm - addOption(String fieldName, String choiceValue, String choiceLabel)
If only it is independent field not depending on any other field then it would work rhe way you are doing but otherwise if there is dependency. You need to follow above.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
Cc - @Dr Atul G- LNG
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2025 05:47 AM
Hi @ronro2
Try like this:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
if (newValue != '1' && newValue != '2') {
g_form.addOption('u_esito', 'istr','Istruzione');
} else {
g_form.removeOption('u_esito', 'istr');
}
}
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2025 02:28 AM
Hey @Dr Atul G- LNG ! It is not working. Do you see why?
function onChange(control, oldValue, newValue, isLoading) {
// Return if the form is loading or no value is selected
if (isLoading || newValue === '') {
return;
}
// Check if the selected order type is 'change'
if (newValue === 'change') {
// Add 'no_change' as a default option to node_size
g_form.addOption('node_size', 'no_change', 'Inga förändringar');
// Add 'no_change' as a default option to node_amount
g_form.addOption('node_amount', 'no_change', 'Inga förändringar');
// Optionally set the default value to 'no_change'
g_form.setValue('node_size', 'no_change');
g_form.setValue('node_amount', 'no_change');
} else {
// Remove 'no_change' options when other order types are selected
g_form.removeOption('node_size', 'no_change');
g_form.removeOption('node_amount', 'no_change');
// Clear the values
g_form.setValue('node_size', '');
g_form.setValue('node_amount', '');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2025 02:33 AM
@Shivalika can you help here.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2025 06:09 AM
please share your script, it should be an easy one
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