- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2019 01:53 AM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2019 03:03 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2019 01:57 AM
Hi,
try using getDisplayValue();
Cheers
Alberto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2019 01:59 AM
Hi,
(current.sys_updated_on.getDisplayValue());
Should do the trick.
Thanks
Veer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2019 02:20 AM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2019 02:32 AM
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