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.

Calculate duration for "Days Open"

davekox
Kilo Explorer

Hello, I have created a duration field called "Days Open" which I would like to have reflect the total amount of time (in Days) elapsed between between the Opened date and Current date.

I know this has got to be very simple to do so I was looking at the "Duration" field to use as an example, but I haven't been able to find where the code is entered for the calculation. ??

Thanks in advance for any help you can provide. 🙂

7 REPLIES 7

davekox
Kilo Explorer

Thanks for your help, Geoff. I really appreciate it. I am not a developer so pardon me, but I do see where you've got the "end" in the calculation set to the "Work End" field. How can I replace the current.work_end value with the instance current date and time? I basically just need to see the length of time an active incident/task has been open.


Generally work_end does get set to the current time when the task closes or whatever. But if you need to you can set it:



current.work_end = gs.nowDateTime();


Of course you'll only want to do this once. So you should probably have some kind of changesTo() condition on your business rule, or test the work_end before setting it:



if (current.work_end.toString() == '') {
current.work_end = gs.nowDateTime();
}



Hello,



Thanks for the script, but it doesn't work for me. What kind of a field is u_task_duration?


Is the client script a business rule client callable? Sorry for the question, but I am trying to figure out, why it doesn't work.