Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Is possible to add an "IF" in glidefunction:datediff?

MR Carvalho
Tera Contributor

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:

 

Sem título.png

 

 

 

 

 

 

 

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.

3 REPLIES 3

SwarnadeepNandy
Mega Sage

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

Hi, 

I tried this and this seems to be not working as expected. Any updated code available?

 

Thanks ,

Rohith

@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.

David Hepburn, III (he / him) | Paramedic
CSA, Senior Enterprise Application Analyst
ServiceNow DevOps
Children’s Health System of Texas
Dallas, Texas, USA