How to hide a mandatory field using catalog client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi All,
I've written a onChange catalog client script on Subcategory field. whenever a specific subcategory is selected then the description field should be visible and should become mandatory. After Subcategory value changes back to --None-- the description field should be hidden (vice versa). I have written below script. It is not working.
And we are adding category and subcategory choices via catalog client script. As these variables are from Variable set. How can I achieve this same functionality via catalog UI Policy.
if (newValue == 'create_a_new_local_gcajob/sub_family') {
g_form.setDisplay('description', true);
g_form.setMandatory('description', true);
}
else
{
g_form.setMandatory('description', true);
g_form.setDisplay('description', true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi @The Matrix ,
I tried your problem in my PDI and it is working fine for me
Can you please try with UI Policy,
Create UI Policy Action
Result
When Option one is selected description is mandatory
When Option two is selected description is not visible
Please mark my answer correct and helpful if this works for you
Thanks and Regards,
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
try this once -> do clear the description when you are hiding it
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading)
return;
if (newValue == 'create_a_new_local_gcajob/sub_family') { // use correct value to compare
g_form.setDisplay('description', true);
g_form.setMandatory('description', true);
} else {
g_form.setMandatory('description', false);
g_form.clearValue('description');
g_form.setDisplay('description', false);
}
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hope you are doing good.
Did my reply answer your question?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi @The Matrix
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) return;
// Target variable name: 'description'
if (newValue == 'create_a_new_local_gcajob/sub_family') {
g_form.setDisplay('description', true);
g_form.setMandatory('description', true);
} else {
g_form.setMandatory('description', false);
g_form.setDisplay('description', false);
g_form.clearValue('description');
}
}
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
@The Matrix if you feel like I am able to solve the problem .. Please accept the solution on the same !!
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
