Code correction help

Jyoti Tripathi
Giga Guru

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. 

8 REPLIES 8

I tried, but still it is checking going in both if and else if

 

Jyoti Tripathi
Giga Guru

@Ankur Bawiskar : could you please help?

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Jyoti Tripathi 

did you try debugging to see what came for active flag for each record?

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@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