
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2019 08:51 AM
I am new to JavaScript in SN, but I have a good developer's experience in other tools/languages.
I am trying to use a Function field in London release to calculate the datediff between Now and pause_time in a Task_SLA table. According to documentation, and I have already done this, I can do something like this: glidefunction:datediff(resolved_at,sys_created_on), but these are regular fields on an Incident records. I need to use a Current date to subtract pause_time. Is it even possible to use a dynamic date?
I tried the below, but I am getting result of 0 sec
glidefunction:datediff(javascript:gs.nowDateTime(),sys_created_on)
glidefunction:datediff(gs.nowDateTime(),sys_created_on)
glidefunction:datediff(nowDateTime(),sys_created_on)
Please help!!!!!!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2019 10:57 AM
datediff is different than gs.dateDiff. The glidefunction version takes field names as inputs, not date/time values. So you would need another field that stores the current date/time which I am assuming would be an issue for your use case if you are using a function field instead of some other options.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2019 09:39 AM
try this, substitue pause_time based on your script
var gCurrentDate = new GlideDateTime(); //give you current system date
var pause_time = new GlideDateTime('2019-06-17 06:00:00');
var seconds = gs.dateDiff(pause_time,gCurrentDate,true);
gs.print(seconds);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2019 09:44 AM
Yogi, thanks. This works great on regular field, but I am trying to do it on a Function field that was introduced in Kingston.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2019 09:45 AM
Here is the link to that page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2019 10:14 AM
Ok thanks. I am sure you must have tried but just in case you haven't, try swapping the inputs.
glidefunction:datediff(sys_created_on,javascript:gs.nowDateTime())
glidefunction:datediff(sys_created_on,gs.nowDateTime())
glidefunction:datediff(sys_created_on,nowDateTime())