Email notification date field

wakespirit
Kilo Guru

Dear all,

In my email body I am refering a date field as below

update on : {current.sys_updated_on}

By doing so the date time format is not according to user setting.

Is there a way directly in email body to format the field according to user setting ?

regarsd

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

Hi Wakesprit,

Try this code, it will work. I just checked in my dev instance and its working fine. You need to write this in the email scripts

var tz = gs.getSession().getTimeZone();
var gdt = new GlideDateTime(current.sys_created_on);
gdt.setTZ(tz);
var showConvertedDate = gs.getMessage('Created on: {0}', gdt.getDisplayValue());
template.print('<p>' + showConvertedDate + '</p>');

Mark correct and helpful if this works.

View solution in original post

5 REPLIES 5

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi,

try using getDisplayValue();

Cheers

Alberto

Veer MS
Kilo Guru

Hi,

(current.sys_updated_on.getDisplayValue());

Should do the trick.

Thanks

Veer

 

Dubz
Mega Sage

You can't use getDisplayValue in the message body and even using it in a mail script won't return the user time. You can use something like this in a mail script:

var gr = new GlideRecord('sys_user');
if(gr.get(gs.getUserID())){
var getTZ_time = getUserTime(current.sys_created_on, gr.time_zone);
template.print('Update on: ' + getTZ_time);
}

function getUserTime(date,usertimezone){
var timezone = Packages.java.util.TimeZone.getTimeZone(usertimezone);
var gdt = new GlideDateTime(date);
gdt.setTZ(timezone);
var set1 = gdt.getTZOffset();
gdt.setNumericValue(gdt.getNumericValue() + set1);
return gdt;
}

Pooja Mallikarj
Kilo Sage

Hi,

Try with below code.

 

var dateTimeVar = current.variables.start_date;

var gdt = new GlideDateTime(dateTimeVar);

template.print(gdt.getDate());

 

Please mark correct/helpful if it helps for you.

Regards,

Pooja