Script - Check the list of active users in an Assignment Group and when was the last INC record was assigned to user

hanaphouse
Giga Guru

I am trying to find a script that will give me the list of active users within an Assignment Group and when was the list time an INC record was assigned to the user.

I can't find an OOB field in the [incident] table that stores the data. Hope someone can walk me through on which table to query to achieve this requirement.

1 ACCEPTED SOLUTION

Tudor
Tera Guru

Hello,

please test the below:

var grmbm=new GlideRecord("sys_user_grmember");
var sysId = ; //enter your group sys_id here
grmbm.addQuery("group",sysId);
grmbm.query();
while (grmbm.next()){

	var metric = new GlideRecord("metric_instance");
	metric.orderByDesc('sys_created_on');

	metric.addEncodedQuery('definition.table=incident^definition.name=Assigned to Duration^value='+grmbm.user.name);
	metric.setLimit(1);
	metric.query();
	if (metric.next()){
	//	[enter script to save data here]
	}
}

Hope this helps!

 Tudor

View solution in original post

4 REPLIES 4

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Why is this important --> when was the list time an INC record was assigned to the user??

-A

-Anurag

This is for our INC assignment routing conditions.

One use case is:

  • An INC record has been created and assigned to Group A
  • Check the active users of Group A
  • Check the number of tickets for each user in Group A per month
  • Sort the user by number of tickets assigned
  • If there is only 1 user with the least number of INC that month:
    • assign the INC to the user
  • If there is 2 or more users with the least number of INC:
    • assign the INC to the user with oldest assigned INC record

Tudor
Tera Guru

Hello,

please test the below:

var grmbm=new GlideRecord("sys_user_grmember");
var sysId = ; //enter your group sys_id here
grmbm.addQuery("group",sysId);
grmbm.query();
while (grmbm.next()){

	var metric = new GlideRecord("metric_instance");
	metric.orderByDesc('sys_created_on');

	metric.addEncodedQuery('definition.table=incident^definition.name=Assigned to Duration^value='+grmbm.user.name);
	metric.setLimit(1);
	metric.query();
	if (metric.next()){
	//	[enter script to save data here]
	}
}

Hope this helps!

 Tudor

Thank You - This helps the [metric_instance] table.