Display only the date from a datetime field

ceraulo
Mega Guru

Hello!

I have a notification running on the sc_task table. I want to display the due date field from the RITM to the notification.
I can do this by dot walk. However, I only want to display the date section (bold part from the sample) of the value.

Due date: 2020-12-15 16:00:00 PST

Is this possible?

Thanks!

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@ceraulo 

You will require to handle this via email script

Then include that email script in your notification body using ${mail_script:mailScriptName}

(function runMailScript(current, template, email, email_action, event) {

    // Add your code here

var gdt = new GlideDateTime(current.request_item.due_date);

var date = gdt.getLocalDate();

template.print('Date'+ date);

})(current, template, email, email_action, event);

Regards
Ankur

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

View solution in original post

2 REPLIES 2

Narsing1
Mega Sage

Hi,

On the Notification Email Script, you can take like this.

var gdt_duedate = new GlideDateTime(current.<duedate variable>);
var gd_duedate = new GlideDate();
gd_duedate.setValue(gdt_duedate);

var onlydate = gd_duedate.getByFormat("MM/dd/yyyy").toString();

Please mark it as correct answer if your issue resolves.

Thanks,

Narsing

Ankur Bawiskar
Tera Patron
Tera Patron

@ceraulo 

You will require to handle this via email script

Then include that email script in your notification body using ${mail_script:mailScriptName}

(function runMailScript(current, template, email, email_action, event) {

    // Add your code here

var gdt = new GlideDateTime(current.request_item.due_date);

var date = gdt.getLocalDate();

template.print('Date'+ date);

})(current, template, email, email_action, event);

Regards
Ankur

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