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

Hi Rakesh,

I am glad to hear your goal has been achieved.
Saying this, I will appreciate if you close this thread, as answered.
Have a great rest of the day

Regards
Ankur

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

Melissa Berry
Tera Guru

I tried to use the same thing as a function field in a report and its saying 'now is not a supported function , Script error in script.'

Any suggestions?

 

find_real_file.png

I know its late, but I think I found the way to do this if you are a sysadmin or can get them to do it for you.  First create a report formula and just do the datediff() with any two date fields so you can get it saved initially.  The system will auto create a function field on the table named u_rpt_{your function name} (or rpt_your_function)
You can locate this in the table configuration and see the function you wrote in the report builder.  I was able to change the actual function and replace the parameters and use the all lowercase now() method and it let me save... and then my report that was using my report function showed the datediff appropriately.

Bridget Laird
Tera Contributor

I had my admin create it on the table directly - works great!

wai yen
Tera Contributor

I tried to use the same thing as a function field in a report and its saying 'now is not a supported function , Script error in script.'

Any suggestions?

find_real_file.png