ABC group members is not part of Level 1 and Level 2 cost center users

raj149
Giga Guru

Hello Experts,

 

My requirement is 

 

I want users details in a report who is part of ABC group is not part of  cost center table Level1 approver(reference field) and level 2 approver(reference field).

 

 

So I created script include but when i run report it is taking so much of time to get results and instance also not working 

In report the condition is sysID is javascript: TestL1L2Approver();

Is there any mistake in my script 

 

function TestL1L2Approver(){
mem =[];
var grMembers = new GlideRecord('sys_user_grmember');
 
    grMembers.addQuery('group' ,'e5302b2d1b4e11506ece2fc5604bcb5c');
 
    grMembers.query();
 
    while (grMembers.next()) {
 
        var userSysID = grMembers.user.toString();
 
        var Levelone = new GlideRecord('cmn_cost_center');
 
        Levelone.addQuery('u_level_1_approver', userSysID);
 
        Levelone.query();
 
        while (!Levelone.next()) {
 
            var Leveltwo = new GlideRecord('cmn_cost_center');
 
            Leveltwo.addQuery('u_level_2_approver', userSysID);
 
            Leveltwo.query();
 
            while(!Leveltwo.next()) {
 
                mem.push(grMembers.user);
 
            }
        }
    }
return mem;
}
 
 
Best Regards,
Raj
15 REPLIES 15

Hello @Ankur Bawiskar 

 

Tested with above script but no luck , again i can see one user sys_id and he is part of L1 approver.

@raj149 

Did you try running in background script and check the logs?

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

Hello @Ankur Bawiskar 

Tested with background script but i can see all the group members sys_id 

 

FYI

raj149_0-1693832357089.png

 

@raj149 

while pushing into array use toString()

 

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

@Ankur Bawiskar 

Tested with toString as well but again i am getting same result 

for reference on the right side  you can see one user sys_id. he is part of cost center L1 approver 

raj149_0-1693832813134.png