The CreatorCon Call for Content is officially open! Get started here.

Creating Function field using glidefunction:datediff()

Rakesh Goel
Kilo Expert

I want to have a column in the list giving how many days back the incident was created without storing it in the database. Therefore, I do not want to create a database column and maintain it all the time. Therefore, I created a Function field on my table.

By doing: using dictionary-> New -> a record with Function Field = Yes

with Function definition as glidefunction:datediff(sys_created_on,now());

Instead of number of days, it is computing 1969-12-31 23-28-34. I guess that there is a mismatch in the format of sys_created and now(). Can someone please suggest what function do I use instead of now().

 

Thanks in advance.

12 REPLIES 12

Any one received answer for this? I am facing the same issue as well

Lisa Goetz
ServiceNow Employee
ServiceNow Employee

Thanks to the amazing Gurjot Joshi, needed to create a separate "current date" field on the form itself which had a calculated value on the dictionary entry of: 

(function calculatedFieldValue(current) {

// Add your code here
return new GlideDateTime().getDisplayValue()+''; // return the calculated value

})(current);

 

It shows the current date on this new field. Then, since we wanted to calculate the number of days between today's date and a "vacated date" on the form, used: glidefunction:datediff(u_current_date,u_date_vacated)

 

Hope this helps as it appears that the "now()" is producing errors even if syntax is correct.

Hi @Lisa Goetz,

I tried to do that but not working for me. 
I have a calculated field to get the project end date 


 return current.task.top_task.end_date;

 

and I created a function to get the duration between two dates but I am getting nothing on the report