The CreatorCon Call for Content is officially open! Get started here.

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

Can anyone please let me know how to use DurationCalculator for the addition of two duration fields and placing its final value on another duration field?


jwl178
Kilo Contributor

GN,




MGuy's code above makes sense to me. I believe (but could be wrong) that his code makes new time cards and simply adds them together for a sum of total duration.




Either way you will need to create a list of duration values to add together into a total duration field.(via parent relationship) I was thinking that the sys_audit table would hold this list of duration values but creating new time cards is a simpler and more elegant solution.




My apologies, I can understand the process but I'm not a very good coder so I can't help you there.


jwl178
Kilo Contributor

Sorry error in first post.



MGuy's code above makes sense to me. I believe (but could be wrong) that his code makes new time cards and simply adds them together for a sum of total duration. (via a parent relationship)




Either way you will need to create a list of duration values to add together into a total duration field. I was thinking that the sys_audit table would hold this list of duration values but creating new time cards is a simpler and more elegant solution.




My apologies, I can understand the process but I'm not a very good coder so I can't help you there.


marcguy
ServiceNow Employee
ServiceNow Employee

Thanks GN yes the code simply queries the existing timecards that are related to the parent incident as I believe you are creating these already? And then just rolls them up. I'm not near an instance but sure there is already a BR that runs on task_time_worked that rolls this up into the time worked field already on task.



If your using those tables then check that field but if not check that BR out and it will give you a starter to use on your timecard table.



Marc


If anyone can please let me know the example of how two duration values can be added or subtract then i think i would be able to make it workable for my requirement. I haven't seen that part of logic has been shared by anyone.


Any idea where you would like me to hunt?