Is possible to add an "IF" in glidefunction:datediff?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2023 03:39 PM
Hi guys,
I have created a function field in my incident table that is using this glide function: glidefunction:datediff(sys_created_on, resolved_at)
it´s ok but when the resolved field is empty its not making a calculation with the date now. Below is my example:
Please, is possible to add an "if" in my glide function? For example, if resolved_at is empty "get the date now".
Thanks in advance.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2023 05:58 PM
Hello @MR Carvalho,
Try adding an “if” statement in your glide function to handle the case when the resolved_at field is empty. You can use the glidefunction:now() to get the current date/time and compare it with the sys_created_on field. For example, you can write something like this:
glidefunction:if(glidefunction:isnull(resolved_at),
glidefunction:datediff(sys_created_on, glidefunction:now()),
glidefunction:datediff(sys_created_on, resolved_at))
This function will check if the resolved_at field is null, and if so, it will use the current date/time instead. Otherwise, it will use the resolved_at field as usual.
Hope this helps.
Kind Regards,
Swarnadeep Nandy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 05:09 AM
Hi,
I tried this and this seems to be not working as expected. Any updated code available?
Thanks ,
Rohith
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 03:26 AM
@SwarnadeepNandyI believe your intentions were good, and this may have worked for you. However, I do want to ❌strongly caution❌ folks before using this code.
Doing this in the Washington DC version caused a whole host of issues, including loss of the ability to see any dictionary entries, error messages when viewing lists, Internal Server Errors (HTTP 500).
I was able to revert the changes and restore functionality.
CSA, Senior Enterprise Application Analyst
ServiceNow DevOps
Children’s Health System of Texas
Dallas, Texas, USA