Run a Metric definition based on a Schedule

Mazin AliKarar
Mega Expert

Hi all,

 

I would be grateful if someone would tell me how to run a Metric definition based on a Schedule, for instance, "8-5 weekdays" schedule. My goal is to disable the Metric definition from generating Metric Instances outside working hours.  

Parsing and comparing the time manually is my last option.

find_real_file.png

 

Your help is highly appreciated. 

Thanks, 

Mazin 

 

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

Other option is to calculate business duration. I did it using below script and report of the business duration field.

 Scheduled Job - Script

var gr = new GlideRecord("metric_instance");
gr.addEncodedQuery('end!=NULL^business_duration=NULL');
gr.autoSysFields(false); // so that the records don't have system updates
gr.query();
while(gr.next()) {
	var gsBusiness =new GlideSchedule('dcf6c8fedb5d7e007d1bfa0dbf9619db');
	// Get duration based on schedule
	gr.business_duration = gsBusiness.duration(gr.start.getGlideObject(), gr.end.getGlideObject());
	gr.setWorkflow(false); 
	gr.update();
}

View solution in original post

3 REPLIES 3

Mike Patel
Tera Sage

Other option is to calculate business duration. I did it using below script and report of the business duration field.

 Scheduled Job - Script

var gr = new GlideRecord("metric_instance");
gr.addEncodedQuery('end!=NULL^business_duration=NULL');
gr.autoSysFields(false); // so that the records don't have system updates
gr.query();
while(gr.next()) {
	var gsBusiness =new GlideSchedule('dcf6c8fedb5d7e007d1bfa0dbf9619db');
	// Get duration based on schedule
	gr.business_duration = gsBusiness.duration(gr.start.getGlideObject(), gr.end.getGlideObject());
	gr.setWorkflow(false); 
	gr.update();
}

Thank you, it worked just perfect 🙂

This doesn't seem to be working for my instance, has something changed with the duration calculation? Just getting 0 seconds for all entries.