The Zurich release has arrived! Interested in new features and functionalities? Click here for more

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
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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

RaghavSh
Kilo Patron

SN_Learn
Kilo Patron
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
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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader