- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 11:25 PM
I have one catalog item with filed Hardware Type (dropdown: Laptop, Desktop, Monitor, etc.) and justification.
My requirement is If "Hardware Type" is "Laptop" and the "Justification" field is less than 50 characters, display an error message.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 11:32 PM
you can use onChange catalog client script on Justification variable
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg('justification');
// Check if the Hardware Type is 'Laptop'
if (g_form.getValue('hardware_type') == 'Laptop') {
// Check if the Justification field has fewer than 50 characters
if (newValue.length < 50) {
g_form.showFieldMsg('justification', 'Justification must be at least 50 characters long.', 'error');
}
}
}
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
12-26-2024 11:33 PM
Hi @Prakash_S ,
You can write onChange clint script.
if (g_form.getValue('hardware_type') === 'Laptop') {
g_form.setMandatory('justification', true);
if (g_form.getValue('justification').length < 50) {
g_form.showErrorBox('justification', 'Justification must be at least 50 characters for Laptop requests.');
} else {
g_form.hideErrorBox('justification');
}
} else {
g_form.setMandatory('justification', false);
g_form.hideErrorBox('justification');
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 11:32 PM
you can use onChange catalog client script on Justification variable
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg('justification');
// Check if the Hardware Type is 'Laptop'
if (g_form.getValue('hardware_type') == 'Laptop') {
// Check if the Justification field has fewer than 50 characters
if (newValue.length < 50) {
g_form.showFieldMsg('justification', 'Justification must be at least 50 characters long.', 'error');
}
}
}
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
12-26-2024 11:39 PM
you will require 1 more onChange client script on Hardware type
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg('justification');
// Check if the Hardware Type is 'Laptop'
if (newValue == 'Laptop') {
// Check if the Justification field has fewer than 50 characters
if (g_form.getValue('justification').length < 50) {
g_form.showFieldMsg('justification', 'Justification must be at least 50 characters long.', 'error');
}
}
}
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
12-26-2024 11:33 PM
Hi @Prakash_S ,
You can write onChange clint script.
if (g_form.getValue('hardware_type') === 'Laptop') {
g_form.setMandatory('justification', true);
if (g_form.getValue('justification').length < 50) {
g_form.showErrorBox('justification', 'Justification must be at least 50 characters for Laptop requests.');
} else {
g_form.hideErrorBox('justification');
}
} else {
g_form.setMandatory('justification', false);
g_form.hideErrorBox('justification');
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------