Filter out people which are on leave

SnowUserDev
Tera Contributor

Hi Experts,

 

I need help in one logic where in a variable I am getting multiple people. Now what I want to do is I want to remove people who will be absent(their data is present in one table) from that available variable.

How can this be achieved?

1 ACCEPTED SOLUTION

Hi @SnowUserDev ,

 

Try the below code n see if it works or not

var finalusers = '';

var a = user1,user2,user3;

a = a.split(',');

for(var i=0;i<a.length;i++){

var gr = new GlideRecord ('table_name');

gr.addQuery('user_field_name',a[i]);

gr.addQuery('active',true);

gr.query();

if(gr.next()){

//do nothing

}else{

finalusers.push(a[i]);

}

}

gs.info(finalusers);

 

Thanks,

Danish

 

View solution in original post

5 REPLIES 5

AshishKM
Kilo Patron
Kilo Patron

Hi @SnowUserDev,

Please share more technical details about the variable.

If variable is reference to sys_user table and user's absent ( or leave ) data available in any custom table then you can achieve the desire result in following way.

1) create view on user & custom table and user this view in variable.

2) write script include code, to filter the absent users data and get the available user's list

 

-Thanks,

AshishKMishra


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Danish Bhairag2
Tera Sage
Tera Sage

Hi @SnowUserDev ,

 

Could u elaborate a bit more, when u say data is available in the table wht kind of data is available?

Also in the variable when values for people are stored how is it stored?

Comma seperated or in any other way.

 

Thanks,

Danish

 

SnowUserDev
Tera Contributor

Hi @Danish Bhairag2 @AshishKM ,

 

So the variable contains values from a list collector variable let's say variable 

var a = user1,user2,user3

 

In one table I have info related to above user whether they are on leave or not.

If value is present on that table and active then I need to remove that user from "a" variable. In the table the user field is reference field

 

 

Hi @SnowUserDev ,

 

Try the below code n see if it works or not

var finalusers = '';

var a = user1,user2,user3;

a = a.split(',');

for(var i=0;i<a.length;i++){

var gr = new GlideRecord ('table_name');

gr.addQuery('user_field_name',a[i]);

gr.addQuery('active',true);

gr.query();

if(gr.next()){

//do nothing

}else{

finalusers.push(a[i]);

}

}

gs.info(finalusers);

 

Thanks,

Danish