group and department sync
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi all,
I am having issues with syncing two fields.
I have been assigned a task too set the manager of a group to department head in those groups so not empty (synchronise group manager information from the mapped department head) this change in department table will automatically change in the group table.
ITIL group is out of scope and should NOT update when the manager is selected as department head
here are my two business rules.
1.Sync Group Manager from Dept head noITIL >>>>>>>
2.Sync Dept Head to Group Manager no ITIL >>>>>>>>
The issue I am having is that if I select an ITIL group manager as the department head that automatically updates the manager too. The correct department will only feed group. Itil group keep out of scope still - should not be the case
Is there anything in my script which is allowing the ITIL groups to update.
Is there anything I can do to solve this issue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @LJ_23,
The problem is in your first business rule (Sync Group Manager from Dept head). BR 2 is fine.
if (current.getValue('type') == 'itil') {
On "sys_user_group", Type is a list field that stores the sys_ids of Group Type records, not the text “itil”. So this check is never true, and ITIL groups are never skipped. BR 2 already does it correctly, because it looks up the ITIL group type’s "sys_id" first.
Fix for BR 1: use the same approach as BR 2.
// find the ITIL group type
var itil = new GlideRecord('sys_user_group_type');
if (!itil.get('name', 'itil')) {
return; // if the ITIL type isn't found, stop rather than risk updating ITIL groups
}
// skip ITIL groups
var types = (current.getValue('type') || '').split(',');
if (types.indexOf(itil.getUniqueValue()) != -1) {
return;
}
Small fix for BR 2: add this guard right after the ITIL lookup. If the lookup fails, "itilId" stays empty, and groups with no type would then be skipped by mistake.
if (!itilId) {
return;
}
Also confirm that the ITIL record under System Security > Groups > Group Types has the Name itil exactly. If it doesn’t, change the lookup to match.
If this helped to answer your query, please mark it helpful & accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi there @LJ_23
The issue is in your first BR. You're checking current.getValue('type') == 'itil', but the type field stores group type sys_ids, not the name 'itil'
var types = (current.getValue('type') || '').split(',');
if (types.indexOf(itilId) != -1) {
return; // Use continue inside the while loop in BR 2
}