Code correction help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2024 02:31 AM
I have a requirement to assign the manager to user
1. if there are multiple manager profile with same employee number example ABC and ABC1 one is active and another is inactive, then user should be assign to active only
2. if there are multiple manager profile with same employee number example ABC and ABC1 and both are inactive, then user should be assign to inactive only
i was trying in background script
var mgr = 987651;
var tGrmanagers = [];
var fGrmanagers = [];
var grmanager = new GlideRecord('sys_user');
grmanager.addQuery('employee_number', mgr);
grmanager.query();
while (grmanager.next()) {
if (grmanager.active == true) {
tGrmanagers.push(grmanager.sys_id);
gs.info('tGrmanagers: ' + grmanager.sys_id);
}
else{
fGrmanagers.push(grmanager.sys_id);
gs.info('fGrmanagers: ' + grmanager.sys_id);
}
}
But issue is, loop is going in both if and else.. it is pushing both active and inactive.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2024 02:54 AM
I tried, but still it is checking going in both if and else if
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2024 02:55 AM
@Ankur Bawiskar : could you please help?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2024 03:24 AM
did you try debugging to see what came for active flag for each record?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2024 03:47 AM
@Ankur Bawiskar : It is checking for both active and inactive user,
var mgr = 987651;
var tGrmanagers = [];
var fGrmanagers = [];
var grmanager = new GlideRecord('sys_user');
grmanager.addQuery('employee_number', mgr);// there are 2 profiles with 987651 employee number- one is active, another is inactive
grmanager.query();
while (grmanager.next()) {
if (grmanager.active == true) {
gs.info('active: ' + grmanager.active);
tGrmanagers.push(grmanager.sys_id);
gs.info('tGrmanagers: ' + grmanager.sys_id);
}
else{
gs.info('inactive: ' + grmanager.active);
fGrmanagers.push(grmanager.sys_id);
gs.info('fGrmanagers: ' + grmanager.sys_id);
}
}
This is the log-
*** Script: inactive: false
*** Script: fGrmanagers: 0c1bf0a81b588e50eddcfe25cc4bcb82
*** Script: active: true
*** Script: tGrmanagers: 794ab0681b588e50eddcfe25cc4bcb92