Assignment Groups, Notifying Owners
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-30-2023 02:34 PM
I need to send an assignment group owner a notification when someone in their group changes departments. It seems to be working mostly, right up until the GlideRecord query. Logging, I'm seeing my variables populated, but nothing logs for gs.info("Assignment Groups: " + assignGroup), doesn't even say undefined.
(function executeRule(current, previous /*null when async*/ ) {
// Calls event when assignment group changes
//gs.eventQueue('multco.ass.grp.changes',current,current.user,current.group);
if (gs.hasRole('itil')) {
// logging
gs.info("Assignment Group Change: " + gs.hasRole('itil'));
var userID = current.name;
var userRef = userID.toString();
gs.info("Current User ID: " + userID);
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', userID);
gr.query();
while (gr.next()) {
var assignGroup = gr.group.getDisplayValue();
gs.info("Assignment Groups: " + assignGroup);
gs.eventQueue('multco.ass.grp.changes', current, assignGroup);
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-27-2023 01:53 PM
Are you suggesting this be run against sys_user or sys_user_grmember?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-07-2023 02:50 PM - edited ā09-07-2023 02:50 PM
Thank you for your assistance @Mohammad K. Kris is my teammate and he's out for the next few weeks.
This is in a sys_user business rule that runs when Division changes and the role is itil.
We are actually wanting to notify the manager ONLY when the group type = Assignment and the groups Division changes. We have tons of AD groups and each of them are triggering with this current code.
I did some logging and the Previous Div, userId and Manager ID are all producing values (sysids for manager and user, but that's OK), but I'm also getting a lot of blanks for the non-assignment group type. Here's the current code:
(function executeRule(current, previous /*null when async*/ ) {
var userId = current.getUniqueValue(); // user record sys_id
var managerId = ''; // we will need to get this for each group to pass on to our event parm 1
var previousDiv = previous.u_division.getDisplayValue(); // display name of the department for event parm 2
gs.log('Previous Division: ' + previousDiv);
//Next we need to get all the groups our user belongs to
var groupMember = new GlideRecord('sys_user_grmember');
groupMember.addQuery('user', userId);
gs.log('User ID: ' + userId);
groupMember.query();
while (groupMember.next()) {
// for each group we want to get the managers sys_id and trigger the event
managerId = groupMember.group.manager;
gs.log('Manager ID: ' + managerId);
gs.eventQueue('multco.ass.grp.changes', current, managerId, previousDiv);
}
})(current, previous);
Do I need to add this?:
groupMember.addEncodedQuery('group.typeLIKE4f16032ae52d600004dfe3a29c6c4d60')
I'd also like to get the group name in here for the notification, but every time I try to pul lit I get 'undefined'.
Thank you SO MUCH for all your help. I feel like we're very close.