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:39 AM
Hello @Jyoti Tripathi
Use this 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.getValue('sys_id'));
gs.info('tGrmanagers: ' + grmanager.getValue('sys_id'));
}
else{
fGrmanagers.push(grmanager.getValue('sys_id'));
gs.info('fGrmanagers: ' + grmanager.sys_id);
}
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 02:41 AM
it is again picking both
*** Script: fGrmanagers: 0c1bf0a81b588e50eddcfe25cc4bcb82
*** Script: fGrmanagers: 794ab0681b588e50eddcfe25cc4bcb92
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 04:17 AM - edited 02-09-2024 05:44 AM
Hi @Jyoti Tripathi ,
var mgr = ""; //Employee Number
var tGrmanagers = [];
var grmanager = new GlideRecord('sys_user');
grmanager.addEncodedQuery('employee_number=' + mgr);
grmanager.query();
while (grmanager.next()) {
if (grmanager.active) {
tGrmanagers.push(grmanager.manager.sys_id.toString());//To push active account manager sys id.
}
}
gs.info(tGrmanagers);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 02:51 AM - edited 02-09-2024 02:51 AM
Hi @Jyoti Tripathi ,
Can you try with else if(grmanager.active==false) instead of else
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand