- 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
‎01-03-2021 09:32 PM
Hi,
So basically you want to show incidents belonging to child groups as well for the Assignment groups present in the table
Unless there is an incident assigned to that child group it won't show in the query business rule
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
‎01-03-2021 09:48 PM
Hi Ankur,
Yes, I want to show child group incidents as well.
There are incidents assigned to child groups, total of 7 incidents. But the business rule is not returning incidents belonging to all child groups.
The child group details are captured correctly, as can be seen in the snapshots.
Is anything incorrect in my script. I spent quite some time checking but no go.
Regards,
Anitha
- 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
‎01-04-2021 10:42 AM
Hi Ankur,
This is working perfectly. Parent Group Members can see their Group's + Child Group records
But one small glitch. OOTB functionality - Child group members get added as parent Group members (although not seen in group members). Both the below return the parent groups as well.
getMyGroups() and Assignment Group -> "isdynamic" -> one of my Groups
https://hi.service-now.com/kb_view.do?sysparm_article=KB0681349
I used the below script which is working
(function executeRule(current, previous /*null when async*/) {
var groupsArray = [];
var user = gs.getUserID();
var grMember = new GlideRecord('sys_user_grmember');
grMember.addQuery('user', user);
grMember.query();
while(grMember.next())
{
groupsArray.push(grMember.group);
}
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);
In the above scenario, we would need to modify the MyGroupsWork right to show only Groups where user is explicitly a member + the child groups only.
Also should add query to show records where openedby, caller and watchlist is matching.
Is my thought process correct ?
Would Making the above changes mean a lot of deviation from OOTB which may result in upgrade issues or break some other functionality elsewhere ?