- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2022 05:59 AM
Hi all,
How do I access the ID data from the metric_instance table, it being a document type field?
I want to run a freeform /BG script on the metric_instance table, but for my query I need to access the value of 'active' and 'closed_at' on the ID record. Apparently you can't just access it like: 'id.active' like a reference field.
Any help is appreciated!
TIA,
Annika
var inst = new GlideRecord("metric_instance");
inst.addQuery('definition','6739a66b1b316850629d4002cd4bcb0d');
inst.addQuery('calculation_complete',false);
inst.addQuery('id.active',false);
inst.addQuery('duration', '');
inst.query();
while(inst.next()){
inst.duration = gs.dateDiff(inst.start.getDisplayValue(), inst.id.closed_at.getDisplayValue());
inst.calculation_complete = true;
inst.end = inst.id.closed_at.getDisplayValue();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2022 11:19 PM
Hi Filipe,
Thanks! For anyone who might find this helpful, this is the finalized script that ended up working for us:
var inst = new GlideRecord("metric_instance");
var qc = inst.addQuery('definition','6739a66b1b316850629d4002cd4bcb0d');
qc.addOrCondition('definition', '6b1926ab1b316850629d4002cd4bcb32');
inst.addQuery('calculation_complete',false);
inst.addQuery('duration', '');
inst.query();
while(inst.next()){
var tableName = inst.table.toString();
var ticket = new GlideRecord(tableName);
ticket.addQuery('sys_id', inst.id.toString());
ticket.addQuery('active', false);
ticket.query();
if (ticket.next()){
inst.duration = gs.dateDiff(inst.start.getDisplayValue(), ticket.closed_at.getDisplayValue());
inst.calculation_complete = true;
inst.end = ticket.closed_at.getDisplayValue();
inst.update();
}
}
Best,
Annika

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2022 12:55 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2022 11:19 PM
Hi Filipe,
Thanks! For anyone who might find this helpful, this is the finalized script that ended up working for us:
var inst = new GlideRecord("metric_instance");
var qc = inst.addQuery('definition','6739a66b1b316850629d4002cd4bcb0d');
qc.addOrCondition('definition', '6b1926ab1b316850629d4002cd4bcb32');
inst.addQuery('calculation_complete',false);
inst.addQuery('duration', '');
inst.query();
while(inst.next()){
var tableName = inst.table.toString();
var ticket = new GlideRecord(tableName);
ticket.addQuery('sys_id', inst.id.toString());
ticket.addQuery('active', false);
ticket.query();
if (ticket.next()){
inst.duration = gs.dateDiff(inst.start.getDisplayValue(), ticket.closed_at.getDisplayValue());
inst.calculation_complete = true;
inst.end = ticket.closed_at.getDisplayValue();
inst.update();
}
}
Best,
Annika
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2022 06:39 AM
Hi Annika,
Apparently ID on metric instance is not a reference field to dot walk. The field type is document, So what you can do is, take the sys_id from the id field and then write a gliderecord query on incident table