How to get duration for Task created to closed ?

yandp
Tera Guru

Hello all, 

I have a custom application, extended "task" table.

i need to get the task duration, like from record created to closed, taken how many day.

Refer to table below, there time data is all empty, how to make this available?

Thank you.

find_real_file.png

 

1 ACCEPTED SOLUTION

Sai Kumar B
Mega Sage
Mega Sage

@yandp 

You can use metric definition on your custom table, You can refer to the OOTB Incident  metric definition in the metric_definition table and modify the script accordingly

find_real_file.png

 

 

View solution in original post

5 REPLIES 5

Vishnu Prasad K
Giga Guru

Hi Yandp,

 

You can solution this in 2 approaches.

1. Create an before update BR to execute when the state changes to Closed and use the below code

 

var create = new GlideDateTime(current.getValue('sys_created_on'));

var closed = new GlideDateTime(current.getValue('sys_closed_on));

var time = GlideDateTime.subtract(create,closed);

current.setValue('time_worked', time);

 

Do the appropriate formatting and converting the difference into days, hours etc. based on your requirement.

 

2. You can create a Metric definition that automatically calculates the duration between 2 specific states (Need to apply filters). Write a BR to copy this value to Time worked field.