How to read values of a field with seconds,minutes and hours

Community Alums
Not applicable

Hi Team,

 

I have created a metric definition for a custom field NextAction in servicenow. 

 

Ankur20_0-1731410012061.png

 

For a Case number it can have multiple records. If you see the below screenshot with Column Duration.I want to extract sum of values , which have different units like seconds,minutes,hours etc

Ankur20_1-1731410095619.png

 

Can someone tell how to achieve it? I wrote below script but its not working properly.

 

var rpchdMin = '';
        var rpchSec = '';
        var metric_rpch = new GlideRecord('metric_instance');
        metric_rpch.addQuery('id', current.sys_id);
        metric_rpch.addEncodedQuery('value=Resolved Pend Cust Handshake');
        metric_rpch.query();
        gs.info('metric_rpch:' + metric_rpch.getRowCount());
        while (metric_rpch.next()) {
            if (metric_rpch.duration.indexOf('Seconds') != -1) {
                rpchSec = rpchSec + metric_rpch.getDisplayValue('duration');
                gs.info('rpchSec:' + rpchSec);

            }
            if (metric_rpch.duration.indexOf('Minutes') != -1) {

                rpchdMin += metric_rpch.getDisplayValue('duration');
                gs.info('rpchdMin:' + rpchdMin);

            }

        }
1 ACCEPTED SOLUTION

aizawaken
Tera Guru

hi @Community Alums ,

How about changing your code to the yellow part as below?

aizawaken_0-1731417060821.png

 

Then, IF condition looks working.
Could you confirm in your end?

 

Thanks,

View solution in original post

2 REPLIES 2

aizawaken
Tera Guru

hi @Community Alums ,

How about changing your code to the yellow part as below?

aizawaken_0-1731417060821.png

 

Then, IF condition looks working.
Could you confirm in your end?

 

Thanks,

Community Alums
Not applicable

This issue is resolved, there was some mistake from myside.