- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 07:53 AM
I need a scheduled manner to return seconds from epoch. getNumericValue returns milliseconds. Whenever I take any math actions on the return of getNumericValue, the Flow Designer outputs the value in scientific notation.
If I run the very simple code below in a background script (developer toolkit). It returns the appropriate integer value (1643903153). If I run the same code in a Flow Designer Update Record Field Value script it returns in scientific notation (1.643903153E9). I have tried a variety of ways to resolve this but have been unsuccessful so far. Do anyone have an explanation or way to resolve?
I have tried using the Number() function as well as using the toFixed function that I have seen on Stackoverflow. I will be attempting to convert the return of getNumericValue to a string, truncating it, then converting it back to a number. Another option is to just use a Scheduled Job but I'm not quite there yet.
// Backgroun script
var gdt = new GlideDateTime();
var now = gdt.getNumericValue();
now = Math.round(now / 1000);
gs.print(now);
// now == 1643903153
// Flow designer
var gdt = new GlideDateTime();
var now = gdt.getNumericValue();
now = Math.round(now / 1000);
return now;
// now == 1.643903153E9
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 08:26 AM
This was a rookie mistake on my part. The field type I was saving this to was a string so the below code solved my issue.
var gdt = new GlideDateTime();
var now = gdt.getNumericValue();
now = now.toString();
now = now.slice(0, -3);
return now;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 08:26 AM
This was a rookie mistake on my part. The field type I was saving this to was a string so the below code solved my issue.
var gdt = new GlideDateTime();
var now = gdt.getNumericValue();
now = now.toString();
now = now.slice(0, -3);
return now;