How do I access the ID from Metric instance table?

Annika Aaltonen
Kilo Guru

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();


}
1 ACCEPTED SOLUTION

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

View solution in original post

7 REPLIES 7

Hello Annika, Sure? Take your time and then let me know if that worked for you! Best Regards, Filipe Cruz

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

Vishnu Prasad K
Giga Guru

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