To Populate Time Worked field on HR Case form

Poorna7
Tera Expert

We would like for the "Time Worked" field to equal the "Resolved Date" minus the "Created" date.

I am aware of the "Time Worked" (OOB) field which is available on the HR case form and it is auto calculated when ever the user opens the form and update it.But can we use the same field for calculating resolved date minus created date?

and if yes, how can we achieve date?

 

 

6 REPLIES 6

Uncle Rob
Kilo Patron

Technically, yes, but its not a good idea. (Actually a *terrible* idea... especially if you grown into the ITBM side of ServiceNow).

Time Worked is *NOT* the same concept as Duration.

HR Case is an extension of Task so it should have a Duration column that's already calculating the distance between Created and Closed dates.

Thanks Robert but I checked the Duration field,it is not populating any data.

Have you altered OOB states on HR Case?
Just tested this on a clean dev instance and the Duration calculates as soon as state hits closed.

I have checked and modify the script as I want the difference between opened and resolved date in HR Case table which is scoped but my script is not working:

Can you help me what change I need to make in the below script:

var intDuration = 0;
var tempDuration = GlideDateTime.subtract(current.opened_at.getDisplayValue(),current.work_end.getDisplayValue());
if(tempDuration != null && tempDuration != "") {
intDuration = tempDuration / 60;
intDuration = Math.round(intDuration*100)/100;
current.calendar_duration = intDuration;
}