caluculation

SK5555
Tera Contributor

calculate the time duration between when was record created and when the email was trigger

?

ex: duration = email created time  - record created time

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@SK5555 

whenever you are triggering that email you know the now time, you also know on which record email triggered

So pick the sys_created_on time

Get the difference using script something like this in your email script if you wish to send this difference in email body

var nowTime = new GlideDateTime();
var createdTime = new GlideDateTime(current.getValue('sys_created_on'));
var dur = new GlideDuration();
dur = GlideDateTime.subtract(createdTime, nowTime); //the difference between 
template.print(dur.getDisplayValue());

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@SK5555 

whenever you are triggering that email you know the now time, you also know on which record email triggered

So pick the sys_created_on time

Get the difference using script something like this in your email script if you wish to send this difference in email body

var nowTime = new GlideDateTime();
var createdTime = new GlideDateTime(current.getValue('sys_created_on'));
var dur = new GlideDuration();
dur = GlideDateTime.subtract(createdTime, nowTime); //the difference between 
template.print(dur.getDisplayValue());

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@SK5555 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

SK5555
Tera Contributor

why you are used nowtime ?
is there any way with database view ?

@SK5555 

The reason I used now time is because the current time is the time when email was triggered, so you can use that as a reference

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader