- 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-25-2025 02:29 AM
Hey @Ankur Bawiskar !
This is my script:
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', '');
}
}
It is not working however. I've removed the 'no_change' from the variable and tried to add it via the script above.
- 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-25-2025 03:13 AM
@Shivalika & @Dr Atul G- LNG thank you guys!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2025 03:31 AM
Hello @ronro2
I am glad my reply answered your query !!
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY