How to sum of duration field

lucky24
Tera Contributor

Hi Team,

We have have custom choice field called substate which has different value.I have defined metrics to run on this field. This is for Incident table 

the substate value  is caller, vendor, customer. 

so I have to calculate time for each value means how much time ticket was in particular substate  choice value.

but when I changing value to caller and again changed to caller so it's is creating multiple record in metric instance for caller value .

 

find_real_file.png

So I have to sum of all duration and have to populate in incident custom string field.

for that I have written business rule but I faild to get result

find_real_file.png

find_real_file.png

please help me here. I am stuck here from last 3 days .

Please can you help me here with some script .?

Thanks

1 REPLY 1

Mahesh23
Mega Sage

Hi,

Try below code 

var dur ='';
var gr - new GlideRecord('metric_instance');
gr.addQuery('id',current.getValue('id');
gr.addQuery('defination','REPLACE_SYS_ID');
gr.addQuery('value','Caller');
gr.query();
while(gr.next()){
    dur = new DurationCalculator();
    dur =gr.duration.dateNumericValue();

}
    var tab = new GlideRecord('table_name');
    tab.get(current.getValue('id');
    tab.u_substate.setDateNumericValue(dur);
    tab.update();

 

Hope this can help you!