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

Jessica28
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

Jessica28
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 @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

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';
}

 

Jessica28
Tera Guru

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

 

Jessica28_0-1702710862988.png

 

@Jessica28 

Glad to know.

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

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