Client script works inconsistently

Hello,
I have calculated overtime from employee checkin & checkout logs through the custom script. The problem is that overtime and shift hours are set in the field after reloading the browser 2-3 times.


Here’s the code of the custom script

Does anyone have a solution please notify me.
Thanks in advance!