I need to check a list field with gliderecord

Flavio Tiezzi
Kilo Sage

Hello guys,

I have a list type field in the department table that points to the user table. This list field can store more than one user sys id.

I need to check through a gr if any of that sys id is from the current user.

 

Thanks in advance.

1 ACCEPTED SOLUTION

Dan H
Tera Guru

Hi @Flavio Tiezzi 

Here is an example:

var departmentsGR = new GlideRecord('cmn_department');
departmentsGR.get('8898b18a3b700300d901655593efc4aa');

var currentUser = gs.getUserID();
gs.log(currentUser);
if(departmentsGR){
    var userList = [];
    userList.push(departmentsGR.u_users.getValue().toString());
    gs.log(userList);

    if(userList.indexOf(currentUser)){
        gs.log('user found in list');
    }
}

 

Replace 'u_users' with the field name for your user reference field 

Tested and working in my PDI, let me know if you have any other questions.

 

Please mark my answer as Correct/Helpful based on impact

Regards,

Dan H

View solution in original post

2 REPLIES 2

Dan H
Tera Guru

Hi @Flavio Tiezzi 

Here is an example:

var departmentsGR = new GlideRecord('cmn_department');
departmentsGR.get('8898b18a3b700300d901655593efc4aa');

var currentUser = gs.getUserID();
gs.log(currentUser);
if(departmentsGR){
    var userList = [];
    userList.push(departmentsGR.u_users.getValue().toString());
    gs.log(userList);

    if(userList.indexOf(currentUser)){
        gs.log('user found in list');
    }
}

 

Replace 'u_users' with the field name for your user reference field 

Tested and working in my PDI, let me know if you have any other questions.

 

Please mark my answer as Correct/Helpful based on impact

Regards,

Dan H

Community Alums
Not applicable

thank you brother, you helped me with an existential doubt because I had already thought about duplicates many times.