- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 03:41 AM
Hi Guys,
please could anybody help me with the problem with counting of users in a group?
In table sys_user_group I created new colum ("u_group_members",integer, read only) where I want to calculate users in a group, so on the table I created new business rule for counting users. (configuration attached)
When I use this business role, nothing saved to culumn "u_group_members". Please could tou check my configuration of business rule and a code snippet what I attached and help me to solve this issue?
Thank you!
(function executeRule(current, previous /*null when async*/) {
var grpm = new GlideAggregate('sys_user_grmember');
grpm.addQuery('group','=', current.sys_id);
grpm.addAggregate('COUNT','sys_id');
grpm.query();
var groupMembers = 0;
if(grpm.next())
{
groupMembers = grpm.getAggregate('COUNT');
current.u_group_members = groupMembers;
current.update();
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 03:46 AM
Can you please change this code to
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery("group", current.sys_id);
grp.query();
current.u_group_members = grp.getRowCount();
Do not use current.update() in a before business rule.
If u_group_members is a string field then change the line to current.u_group_members = grp.getRowCount().toString();
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 03:46 AM
Can you please change this code to
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery("group", current.sys_id);
grp.query();
current.u_group_members = grp.getRowCount();
Do not use current.update() in a before business rule.
If u_group_members is a string field then change the line to current.u_group_members = grp.getRowCount().toString();
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 04:13 AM
Hello Alikutty,
thanks for your response! I changed the code, but it still doesnt work 😕
Any idea?
Thank you,
PS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 04:19 AM
This should have worked, Can you please copy the code and try the log that I have added?
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery("group", current.sys_id);
grp.query();
gs.log(grp.getRowCount(), "COUNT");
current.u_group_members = grp.getRowCount();
See what count it returns in log.
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 04:26 AM
Hi Pavel,
I tested and the code was working, When you test you should be modifying the group data like description to run this business rule.
Thanks
Please Hit like, Helpful or Correct depending on the impact of the response