getNumericValue() in glide duration type field is returning undefined?

SatheeshKumar
Kilo Sage

I’m trying to extract the duration values from a metric instance record in a GlideRecord, but getNumericValue() is not working and is returning undefined. What are the other ways to access values from a duration field?

In the end, I need to sum the values from two instance records.

Tried both

var gr = new GlideRecord('metric_instance');
gr.query();
if (gr.next()) {

gs.info(gr.duration.getNumericValue())
 
 
var gd = new GlideDuration(gr.getValue('duration'));
var ms = gd.getNumericValue();
gs.info(ms);
}
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@SatheeshKumar 

this is the simple script to get display value and numeric value

var rec = new GlideRecord('metric_instance');
rec.get('089b46dddbeb5610727ee7dcd39619d8');

gs.info('Display value for duration-> ' + rec.duration.getDisplayValue());
gs.info('Numeric value for duration in milliseconds -> ' + rec.duration.getGlideObject().getNumericValue());

AnkurBawiskar_1-1757935355285.png

 

AnkurBawiskar_0-1757935339827.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

SN_Learn
Kilo Patron

Hi @SatheeshKumar ,

 

Please check the below:

var gr = new GlideRecord('metric_instance');
gr.setLimit(1);
gr.query();
if (gr.next()) {
    gs.info(gr.duration.getGlideObject().getNumericValue()); //In milliseconds
}

Output:

*** Script: 5000

 

Refer to SN Docs: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0780039 

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

Ankur Bawiskar
Tera Patron

@SatheeshKumar 

this is the simple script to get display value and numeric value

var rec = new GlideRecord('metric_instance');
rec.get('089b46dddbeb5610727ee7dcd39619d8');

gs.info('Display value for duration-> ' + rec.duration.getDisplayValue());
gs.info('Numeric value for duration in milliseconds -> ' + rec.duration.getGlideObject().getNumericValue());

AnkurBawiskar_1-1757935355285.png

 

AnkurBawiskar_0-1757935339827.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

NISCHITHHEGDE
Tera Contributor
code:
var
rec = new GlideRecord('incident_metric');
rec.addQuery('inc_number', 'INC0710808');
rec.setLimit(10);
rec.query();
while (rec.next()) {
    if(!rec.mi_duration.nil())

    gs.info('Display value for duration -> ' + rec.mi_duration.getDisplayValue());

    gs.info('Numeric value (ms) -> ' + rec.mi_duration.getGlideObject().getNumericValue());
}

Output:

Please view the screenshot