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

how to SUM of multiple duration field?

lucky24
Tera Contributor

Hi Team,

In metrics definition I am getting multiple record when I am changing same value in multiple time (changing value awaiting caller again and again)

find_real_file.png

 

So now I want to sum these duration and have to store in custom field of incident,

I am trying with below code but not get success 

var duration = new GlideDuration(0);
var mi = new GlideRecord("metric_instance");
mi.addQuery("id", current.sys_id);
mi.addQuery("definition", "fc47ec1d2f1341105d0d56e62799b64e");
mi.addQuery("value", "Awaiting Caller");
mi.query();
mi.getRowCount();
// while(mi.next()){
var dur = new GlideDuration();
dur.setValue(mi.getValue('duration'));
duration = duration.add(dur);

// }
current.u_pause_duration= duration.getDisplayValue();
current.u_total_hour=duration;
gs.addInfoMessage(duration.getDisplayValue());
gs.addInfoMessage(mi.getRowCount());
current.update();

 

So how can we achieve it please help me here?

 

please help me here.

 

1 REPLY 1

Mahesh23
Mega Sage

Hi,

Try below code

var dur = new DurationCalculator();

dur =mi.duration.dateNumericValue();

mi.duration.setDateNumericValue(dur);

Hope this can help you!