sn-time-ago showing 8h ago for tickets that were just created

austinn1
Kilo Expert

I have the following code

<sn-time-ago timestamp="d.sys_created_on"></sn-time-ago>

to show how long ago a ticket was created in a sp widget. In testing, I noticed that for tickets that were just created, it shows 8h ago, and as of an hour later, it shows 9h ago. I checked the data in the actual ticket itself and it is correct. Is there something special that needs to be done here? Am I going to have to handle that logic myself?

1 ACCEPTED SOLUTION

austinn1
Kilo Expert

I was getting the display value of the field in the server script. Changed to gr.getValue('sys_created_on') and the proper time difference is shown.

View solution in original post

6 REPLIES 6

Ct111
Giga Sage
I think that time might be calculated from different script include internal. Better to crosschk that and amend that if required. Mark my ANSWER as CORRECT and HELPFUL if it helps

Justin77
Mega Guru

It sounds like a timezone issue.  Are you 8 hours behind UTC?  Checking the directive definition at [instance].service-now.com/scripts/sn/common/datetime/directive.snTimeAgo.js, it looks like there are two scope parameters, 'timestamp' and 'local', and it looks like 'local' is a boolean, so maybe try:

<sn-time-ago timestamp="d.sys_created_on" local="true"></sn-time-ago>

Interesting, this did get me closer but still not quite right. it now shows 2h ago instead of 8h ago for new tickets.

Looks like the directive uses "new Date()" which is javascript's native date API, as opposed to SNOW's GlideDate/GlideDateTime.  "new Date()" should be pulling your machine's time which might be different from your SNOW instance time?  By 2 hours maybe?