Getting multiple findings for a script-only check on Instance Scan

Community Alums
Not applicable

I want to define a Script Only check in Instance Scan, where it should point out all those groups which have no users.

I am getting the name of the group which doesn't have any users, but getting multiple findings for the same. Multiple findings, that too for the same record.

Please look at my script, and see if I can change anything in the script. Because according to me, there is some issue with the script.

Here's the script below:

(function(finding) {

// Add your code here
var group = new GlideAggregate('sys_user_group');
var group_members = new GlideRecord('sys_user_grmember');

group.addQuery('active', 1);
group.addAggregate('COUNT');
group.query();
while (group.next()) {
var no_of_groups = group.getAggregate('COUNT');
var group_names = [];
group_names.push(group.name.toString());

}

for (var i = 0; i < no_of_groups - 1; i++) {
group_members.addQuery('group', group_names[i]);
group_members.query();
if (!group_members.next()) {
finding.setCurrentSource(group);
finding.increment();
}
}

})(finding);

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

Hi there,

I just created quickly a Table Check, works fine. It's a combination of a Table Check with a condition + script.

find_real_file.png

(function (engine) {

	var group_members = new GlideRecord('sys_user_grmember');
	group_members.addQuery('group', engine.current.getUniqueValue());
	group_members.setLimit(1);
	group_members._query();

	if(!group_members.hasNext()) {
		engine.finding.increment();

	}

})(engine);

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

6 REPLIES 6

Community Alums
Not applicable

Hey Mark, thanks for the solution. It's working great now.

But the logic in the script was also same. You have any idea that why it isn't working in script? Please let me know if you have any idea on this.

I have to reproduce your Scan Check to answer that. Just didn't reproduced yours 🙂

Didn't because I noticed it being a Script Only check, while for what you are asking a Table Check just suits better. So immediately clicked a new Table Check together within 1 minute, tested, works.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn