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.

How to add two duration fields

manish123
Giga Guru

Hi All,

On Incident page, we have Time Card entry tab. And on that there is Duration field which is getting calculated from two other fields as Start Time and End Time. Therefore suppose a single incident should have multiple Duration added. Now on incident there is Total Duration field where i would like the addition of all these Duration for Time Card entries. Can anyone please let me know how can i do it?

33 REPLIES 33

marcguy
ServiceNow Employee
ServiceNow Employee

I will need to check on an instance but I'm sure durations are stored as numeric values so should be able to use simple + - etc or > <



easy way to find out is get the tool to print what it's seeing in those fields by either using



gs.log(current.u_duration_field);


gs.addInfoMessage(current.u_duration_field);



if they are not numeric values then there are ways to convert them like .getNumericValue() but I'm pretty sure they are stored as a numeric value. will confirm when I'm near an instance again today.


Does you meant to say   to get the value of Duration field   through gs.addInfoMessage(current.u_duration_field.getDisplayValue()); I tried with that however its not returning anything i tried with getValue() too.


I used :- gs.addInfoMessage('Hello :' + current.u_duration_field.getDisplayValue());


Its returing Hello : Undefined


marcguy
ServiceNow Employee
ServiceNow Employee

How about current.u_duration_field?


I tried but it didn't display anything.