- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 09:02 AM
Hi Team,
I have a reference field named asset tag which refers hardware table in a catalog item. Also i have an another field called location which is autopopulated according to the location value in hardware table with respect to corresponding asset tag in hardware table. I want populate a message that location field is empty when location field is empty. I have written a catalog client script but it is working in both scenereo that it is showing message both when location field is empty as well as when location field is not empty.
Please take a look on the pics. for more info.
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 06:43 PM
you should write onChang catalog client script on Asset tag variable and populate location and if location empty then show message
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
g_form.clearMessages();
if (newValue == '') {
g_form.clearValue('location'); // location variable name here
}
var ref = g_form.getReference('asset_tag', callBackMethod); // requestedFor variable name
}
function callBackMethod(ref) {
if (ref.location)
g_form.setValue('location', ref.location); // location variable name here
else
g_form.addInfoMessage('Location empty please fill');
}
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 05:18 PM
Hi @Ritika22 ,
Try below script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var lct = g_form.getValue('location');
if (!lct) {
g_form.addErrorMessage('Location is empty please fill it.');
} 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-26-2024 06:20 PM
Hello @Ritika22 ,
If your client script is on location field change, then just do below -
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
g_form.addInfoMessage("No value");
return;
}
g_form.addInfoMessage("value");
//Type appropriate comment here, and begin script below
}
Let me know if this worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 06:43 PM
you should write onChang catalog client script on Asset tag variable and populate location and if location empty then show message
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
g_form.clearMessages();
if (newValue == '') {
g_form.clearValue('location'); // location variable name here
}
var ref = g_form.getReference('asset_tag', callBackMethod); // requestedFor variable name
}
function callBackMethod(ref) {
if (ref.location)
g_form.setValue('location', ref.location); // location variable name here
else
g_form.addInfoMessage('Location empty please fill');
}
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