- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 08:51 PM
Hello,
I have a date and time variable on the RITM that I need to check to see if it is empty or not.
I tried this code in email script, but it is not working: Thank you
if (current.variables.startDate.nil()) {
template.print('Date is invalid);
} else {
template.print('Date is valid);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 11:15 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2023 08:59 AM
Hi @Jessica28
In mail script you already have the current object using which you can dot walk to RITM table, no need to do GlideRecord on RITM table.
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 08:57 PM
Hi @Jessica28 ,
It seems like there's a small syntax error in your code. You're missing a closing quote in the 'Date is invalid' string, and there's a typo in the 'template.print' function. Here's the corrected code:
if (current.variables.startDate.nil()) {
template.print('Date is invalid');
} else {
template.print('Date is valid');
}
Make sure to close the quote properly in 'Date is invalid'. Also, ensure that you have a closing parenthesis for the `template.print` function.
If this still doesn't work, you may want to check if the variable name 'startDate' is correct and matches the actual variable name on your RITM form. Additionally, consider checking if there are any JavaScript errors in the ServiceNow logs that might provide more insights into the issue.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 09:42 PM
Hi @Jessica28 ,
You can also try something like this
if (current.variables.startDate == '') {
template.print('Date is invalid');
} else {
template.print('Date is valid');
}
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 09:42 PM
Hello @Danish Bhairag2
I tried using a different date that I know for sure that this date variable is empty, but it is still printing "Date is valid'. I really don't where I screwed up.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 09:45 PM
From where is the email script getting called?
Hope it's from the notification which is created on RITM table or some table where the variable is present.
Thanks,
Danish