- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2021 08:24 PM
Hi All,
We are having 3 level of Group hierarchy. the 3rd level of Group is used for Task Assignment.
1st and 2nd level is for visibility and reporting.
Members of any assignment Group should see their records + records of the Child Groups.(and Child's Child)
I have referred to the below link and modified the script to find child group and add them to the array. The original script was pasted by
https://community.servicenow.com/community?id=community_question&sys_id=925b8721db9cdbc01dcaf3231f9619a9
(function executeRule(current, previous /*null when async*/) {
var myUserObject = gs.getUser();
var myUserGroups = myUserObject.getMyGroups();
var groupsArray = new Array();
var it = myUserGroups.iterator();
var i=0;
while(it.hasNext()){
var myGroup = it.next();
groupsArray[i]=myGroup;
gs.addInfoMessage(i+ "=" + groupsArray[i]);
i++;
var gr = new GlideRecord('sys_user_group');
gr.addQuery('parent',myGroup).addOrCondition('parent.parent',myGroup);
gr.query();
while(gr.next())
{
groupsArray[i]=gr.sys_id;
gs.addInfoMessage(i + "=" + groupsArray[i]);
i++;
}
}
var qc = 'assignment_group.sys_idIN'+groupsArray;
current.addEncodedQuery(qc);
})(current, previous);
The script is adding the child groups to the array but is not displaying the Incidents.
As per the logging message, Incidents belonging to 6 different groups should be returned. There are incidents assigned to each of the Group. But some groups are getting skipped. Could someone help here fix the issue.
The actual result should be like below -
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2021 09:57 PM
Hi,
Try this updated script once
(function executeRule(current, previous /*null when async*/) {
var groups = j2js(gs.getUser().getMyGroups().toArray());
var groupsArray = groups.toString().split(',');
var arr = [];
var gr = new GlideRecord('sys_user_group');
gr.addQuery('parent', 'IN', groupsArray).addOrCondition('parent.parent', 'IN' ,groupsArray);
gr.query();
while(gr.next()){
arr.push(gr.getValue('sys_id'));
}
var arrayUtil = new global.ArrayUtil();
var finalArray = arrayUtil.concat(groupsArray,arr);
finalArray = arrayUtil.unique(finalArray);
var qc = 'assignment_group.sys_idIN' + finalArray;
current.addEncodedQuery(qc);
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2022 06:36 AM
Hi anithanarayan,
Did you get the solution code where you also want to add a query for opened by, caller and watchlist?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2022 06:18 AM
Hi Ankur,
I want to add one more condition into this. I tried with different combinations but it's not working. So, please help me out here.
Following is my scenario -
If the user is caller of the incident and also if he is part if parent group (Consider Parent group A and Parent Group B. The restriction here is members of Parent group A cannot see records of Parent group B and vice versa. This condition is able to achieve using the script you have provided) But now I want to add another condition.
If user is caller and member of Parent group A, then that incident record should be visible even if that incident is assigned to one of assignment groups of Parent group B.
Ideally, the user cannot be able to see the record is it is assigned to one of assignment groups of Parent group B. But if the user is caller, then he will be able to see it.
How to put this scenario in the the existing code that you have provided.
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2024 09:44 AM - edited ‎07-09-2024 10:20 AM
Hi @Ankur Bawiskar ,
It is Appling for all groups.
Can you help, it should apply only for particular groups.
Thanks,
Anil!