Script a Function Field to get duration from Now back to Pause Time

dgarod
Kilo Guru

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!!!!!!

1 ACCEPTED SOLUTION

User658787
Mega Guru

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. 

View solution in original post

9 REPLIES 9

Yogi3
Kilo Guru

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);

dgarod
Kilo Guru

Yogi, thanks. This works great on regular field, but I am trying to do it on a Function field that was introduced in Kingston. 

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())