- 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
‎03-31-2022 06:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2022 06:39 AM
Hi Filipe,
Thanks for your reply!
This is what the XML looks like as an example:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2022 06:48 AM
Hello!
Yes, the table field!!
You can perform a gliderecord with:
var gr = new GlideRecord(current.table);
gr.get(current.id);
gs.print(gr.active);
Please mark my answer as correct and helpful if it is relevant for you.
Best Regards,
Filipe Cruz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-01-2022 12:50 AM
Thanks Filipe, please allow me some time to check this solution and I will get back to you!