How do you create a requests metric for when an item is assigned to a user?

Ryan Ganser
Giga Contributor

We need to track when a request is assigned to a member of our team, the use case is that we want to create a metric that all items are assigned within two hours of them being created. I believe this can be done easier with incidents metric field, I am not sure how you do this with requests.

I've attempted to follow this guide on creating a metric but I think this may be beyond my skill set to script this.

I appreciate your help!

4 REPLIES 4

Deepak Ingale1
Mega Sage

Could you please provide the table you will be using? Is it sc_request or sc_req_item or sc_task?

 

Deepak Ingale1
Mega Sage

Hello,

 

I created a metric for incident assignment, you can use same logic for other table also, just copy and paste the code and it should work.

I have tested it for 1 minute and it is working fine for me, that piece of code i have commented out in script.

 

 

find_real_file.png

 

// variables available
// current: GlideRecord -  target incident
// definition: GlideRecord -  (this row)
if (!gs.nil(current.assigned_to)) {
	  createMetric(current);
}

function createMetric(current) {
	var mi = new MetricInstance(definition, current);
	if (mi.metricExists()) {
		return;
	}
	
	var gr = mi.getNewRecord();
	var time = gs.dateDiff(current.getValue("sys_created_on"), gs.nowDateTime(), true);
	var timeInHours = parseInt(time / (60*60));
	if (timeInHours < 2) {
		gr.field_value = true;
	}
// 	var timeInMinutes = parseInt(time / 60);
	
// 	if (timeInMinutes < 1 ){
// 		gr.field_value = true;
// 	}

	else {
		gr.field_value = false;
	}
	gr.field = null;
	gr.calculation_complete = true;
	gr.insert();
}

Thank you, I'll test this early next week!

Pulling in a member from my programming team to assist, this may take a little bit but will follow up. I appreciate your help!