We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to check date and time variable if it is empty or not using email script?

JessicaM6884345
Tera Guru

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);

 

 

2 ACCEPTED SOLUTIONS

JessicaM6884345
Tera Guru

Thank you so much for your help. I think I got it working now.

 

Jessica28_0-1702710862988.png

 

View solution in original post

Hi @JessicaM6884345 
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

View solution in original post

12 REPLIES 12

Hi @Saurabh Gupta  

Your code below is working out perfectly. I will replace my version with yours. Awesome, I learned something new today. Thanks to you and the other helpers.

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var date=current.sysapproval.variables.select_end_date_time.getDisplayValue();
var msg="Date is not valid"
if (date)
{
msg='Date is valid';
}

 

JessicaM6884345
Tera Guru

Thank you so much for your help. I think I got it working now.

 

Jessica28_0-1702710862988.png

 

@JessicaM6884345 

Glad to know.

Please close the thread by marking your own response as correct.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader