How can I create report of users , who haven't action on any incident , problem, change ?

somya-gupta25
Tera Contributor
 
11 REPLIES 11

You can use the following script in Scripts - Background to see:

 

var usr = new GlideRecord('sys_user');
usr.addActiveQuery();	// to process only active users
usr.query();
var noUsers = usr.getRowCount();
var noUsersNotTask = 0;
while (usr.next()) {
//	gs.info('Checking: ' + usr.name);
	var tsk = new GlideRecord('task');
	tsk.addQuery('assigned_to', usr.sys_id.toString());
	tsk.addOrCondition('sys_created_by', usr.sys_id.toString());
	tsk.addOrCondition('opened_by', usr.sys_id.toString());
	tsk.query();
//	gs.info('Found ' + tsk.getRowCount() + ' records');
	if (!tsk.next()) {
		noUsersNotTask++;
		gs.info('user has not been assigned to, created, or opened any task: ' + usr.name);
	}
}
gs.info('Number of users not assigned to, created, or opened any task: ' + noUsersNotTask + ' out of ' + noUsers);

shows those not assigned to, created by, or opened by any task record. Add additional query on sys_class_name if you only want to the INC, CHG, and PRB records.

Thanks for sharing the script, @Bert_c1. Could you please let me know how we can achieve the same using a report?

First, the script or a report for the same may cause performance hit. The data comes from two tables, so I report for that is more complicated than my knowledge on Reporting. I don't even know if a database view can provide the relationship needed.

@somya-gupta25 

May I know the use-case for this requirement?

you can determine this easily but what if INC001 was assigned to Abel and then later got assigned to Beth.

In this case Abel will be excluded from your condition.

you can check below link for script which uses GlideAggregate for better performance

Get All the Users who has not been assigned a task? 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Vrushali11
Tera Contributor

Hello @somya-gupta25 ,

Did you achieve this requirement , I am having same requirement to Query the users who have not worked on any task(INC,sc_task).