Populate message when variable value is empty.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 07:59 PM
Hi
There is a catlog item , In catlog item thre is two varibale "asset tag" type is refence and "location" type is refence.
once asset tag is choce then location is autopopulate.
my requirement is
When "location" varibale value is empty then showing error massage, if varibale contain any value then message is not showing.
i write below onchange client script but not working properly please modifay this script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 08:15 PM
Hi @b__BiswabhusanD ,
Use below script it will work, your script not working because when you are using clear messages need to remove newValue in script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var locationValue = g_form.getValue('location');
if (!locationValue) {
g_form.addErrorMessage('Please select a location.');
} else {
g_form.clearMessages();
}
}
If my response helped, please mark it as the accepted solution ✅ and give a thumbs up👍.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 08:30 PM
why not make location variable as mandatory and you won't require any script?
update script as this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '') {
g_form.addErrorMessage('Please select location value');
} else {
g_form.clearMessages();
}
}
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