Milliseconds to GlideDateTime in scoped application
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2016 03:16 AM
In a scoped application: how do I set a millisecond epoch value from an API to GlideDateTime?
I have tried this
var dt = new GlideDateTime();
dt.setNumericValue(1476024386630);
gs.info(dt.getValue());
But I only get:
java.lang.SecurityException: Function setNumericValue is not allowed in <scopename>. There is no alternative for this method Caused by error in <refname> at line 12 |
setNumericValue() is legacy, but works fine in Global.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2016 03:28 AM
Use add() and subtract()
var gdt = new GlideDateTime();
gdt.subtract(gdt.getNumericValue());// gets the date to 0
gdt.add(1476024386630);// The milliseconds you want to get in the date
gs.info(gdt.getNumericValue());
gs.info(gdt.getDisplayValue());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-11-2016 12:34 PM
Thanks! Works like a charm!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2019 04:00 PM
A cleaner method is to use setValue(milliseconds) instead of subtract then add.
The add subtract also worked for me.
Edit: Initially it didn't appear to work for me because of an issue with one of my transform maps.
My milliseconds from epoch was 1565123722502 which is Tuesday, August 6, 2019 1:35:22.502 PM PST
But when i inspect the table i inserted into, i see 2019-08-07 03:35:22
I traced the root cause to writing the GlideDateTime.toString() into the import set as UTC then the transform map assumes the string is in local time, when it's really in UTC. I resolved this by inserting into the import set using getDisplayValue().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-06-2019 04:04 PM
Nevermind, I get the same result with .setValue() . It might have something to do with the interaction with import sets.