Get metric instance attributes for a state based record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2024 01:20 PM - edited 02-01-2024 01:59 PM
trying to get a metric instance record based on task based table like incident to retrieve the duration of the state like "New", "In Progress".
Using the below script to retrieve just one record (as there might be multiple instances for the same state record). But seems like missing something and it doesn't return anything. Please advise.?
// incident record number: INC0010012; id: 05df73db9333f510100a76de3bba1078
// metric instance id: 1ff3a57593484210100a76de3bba10be
var miInst = new GlideRecord('metric_instance');
miInst.addQuery('id', 'Incident: INC0010012');
miInst.addQuery('definition.name', 'In Progress');
miInst.setLimit(1);
miInst.query();
var fields = miInst.getFields();
for (var i = 0; i < fields.size(); i++) {
var field = fields.get(i);
var name = field.getName();
var value = field.getDisplayValue();
gs.print(i + ". " + name + "=" + value);
}
If I give metric instance id, I get the list of all attributes as below. Since I want to drive this script from incident record, I query based on incident number and somehow it doesn’t like id, definition name.
var miInst = new GlideRecord('metric_instance');
miInst.get('1ff3a57593484210100a76de3bba10be');
miInst.setLimit(1);
miInst.query();
var fields = miInst.getFields();
for (var i = 0; i < fields.size(); i++) {
var field = fields.get(i);
var name = field.getName();
var value = field.getDisplayValue();
gs.print(i + ". " + name + "=" + value);
}
Output:
*** Script: 0. start=2024-01-30 14:13:55
*** Script: 1. sys_mod_count=0
*** Script: 2. calculation_complete=false
*** Script: 3. sys_updated_on=2024-01-30 14:13:55
*** Script: 4. duration=
*** Script: 5. business_duration=
*** Script: 6. sys_updated_by=system
*** Script: 7. sys_created_on=2024-01-30 14:13:55
*** Script: 8. field_value=1970-01-01 00:17:41
*** Script: 9. definition=In Progress
*** Script: 10. end=
*** Script: 11. id=Incident: INC0010012
*** Script: 12. value=17 Minutes
*** Script: 13. table=incident
*** Script: 14. sys_created_by=system
*** Script: 15. field=time_worked
*** Script: done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2024 06:12 PM
Found the issue, seems like missed the next() call on the GlideRecord object.