Onchange client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 06:19 AM
I have written the below onchange client script to make Subcategory mandatory when the Category is Software but it is not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 06:58 AM - edited 12-19-2023 07:01 AM
Hello @GBS
Can you please verify once your category choice value i.e. is it "software" or "Software".
and then use the same script which you are using and I also have tested it from my end on incident table and its working perfectly fine.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// Check if the form is still loading or if the field is empty
if (isLoading || newValue === '') {
return;
}
// Get the value of the 'category' field
var category = g_form.getValue('category');
g_form.addInfoMessage("Category - " + category);
// Check if the category is 'Software'
if (category == 'Software') {
g_form.addInfoMessage("Inside if ");
g_form.setMandatory('subcategory', true);
} else {
g_form.addInfoMessage("Inside else");
g_form.setMandatory('subcategory', false);
}
}
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Regards,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 07:12 AM
@Aniket Chavan choice value is 'software'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 07:22 AM - edited 12-19-2023 07:24 AM
Hello @GBS
Then please check if there is any existing logic present or not? like UI policy or existing client script, you can navigate to configure<all and verify there once.
Please let me know your views on this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 07:11 AM
@GBS : Assuming that you have created the onChange client script in the category field, you can directly use newValue to check the value. Please also check the backend name of subcategory is correct or not.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// var category = g_form.getValue('category');
if (newValue == 'software') {
g_form.setMandatory('subcategory', true);
} else {
g_form.setMandatory('subcategory', false);
}
}
If this still doesn't work, check if there are existing logics in client scripts with a higher order than the current one and also UI policies, as they get the highest precedence.