
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
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());
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
This should be simple, did you refer :
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Monday
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());
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader