Convert UTC to Time Zone (US/Eastern) from GlideRecord query output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2015 07:08 AM
I'm relatively new to ServiceNow development and have encountered an issue that seems very simple but has thwarted me, thus far. I've referenced:
Re: How to convert GMT date to ESTand other entries, but haven't been able to figure it out yet.
In a workflow script, there's a GlideRecord query (called, "sysapproval") that pulls some change request variables that are sent to an OnBase approval engine in an XML payload. The fields, "current.sysapproval.start_date" and "current.sysapproval.end_date" are currently output in UTC. Times need to be converted to system time (US/Eastern) or via the java time zone utilities: ("America/New_York"). Because these times aren't actually displayed in ServiceNow, they don't get automatically converted to the system time zone (US/Eastern).
I've tried to do this time zone conversion within the payload function via the GlideDateTime setTZ(tz) method: GlideDateTime - ServiceNow Wiki
var tz = Packages.java.util.TimeZone.getTimeZone("America/New_York");
var ps_dt = new GlideDateTime(current.sysapproval.start_date);
var plannedStartDt = ps_dt.setTZ(tz);
var pe_dt = new GlideDateTime(current.sysapproval.end_date);
var plannedEndDt = pe_dt.setTZ(tz);
However, when I do this, the resulting values in the XML get set to "undefined" and the approval engine chokes on the payload:
<Property><Name>Planned Start</Name><Value>undefined</Value></Property>
<Property><Name>Planned End</Name><Value>undefined</Value></Property>
I've tried to do this just about every alternative way I can think of but haven't had any success. What am I missing?
Thanks,
Keith
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2018 01:06 AM
Hi All,
Did anyone worked on translate one time zone to another time zone in Service Now.
The issue is we are converting the change request creation time to another time zone( like Us/Eastern). Here User profile time zone is IST. But the time conversion is not happening. We have used the below methods. But the result is not expected. We are in Jakarta currently.
Method1:
var createdDate = new GlideDateTime("2018-03-15 13:20:12");
gs.print("createdDate "+createdDate );
var tz = Packages.java.util.TimeZone.getTimeZone("US/Eastern");
createdDate.setTz(tz);
gs.print("createdDate "+createdDate.getDisplayValue());
gs.print("createdDate "+createdDate.getDisplayValueInternal());
Method2:
var createdDate = new GlideDateTime("2018-03-15 13:20:12");
var tz = Packages.java.util.TimeZone.getTimeZone("US/Eastern");
createdDate.setTZ(tz);
var timeZoneOffSet = createdDate.getTZOffset();
createdDate.setNumericValue(createdDate.getNumericValue() + timeZoneOffSet);
gs.print('Eastern time: '+createdDate);
Please let us know if anyone can help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2018 01:44 AM
If it's a scoped application, then setTZ won't work as it's not allowed.