Removing an entry from a list type field

etabalon
Mega Expert

Good day!

How can I remove/delete a value from a list type field.

I have this line of code (BR):

var updated_users = current.u_alternates.split(",");

where: updated_users=9dcc49ce59a3300005f195d0601f5ab3,donald.duck@disney.com,d1cc49ce59a3300005f195d0601f5ad6

these are sys_ids from sys_user table.

What I wanted to do is to loop and check each value and if it didn't find a match on the sys_user table, I wanted to remove from the updated_users variable.

 

for(var i = 0; i < updated_users.length; ++i){
var found = false;

var grNew = new GlideRecord('sys_user');
grNew.addQuery('sys_id', updated_users[i]);
grNew.query();
while (grNew.next()){
found = true;

}

if (found == false){

// I need a statement/systax how to remove this entry from the updated_users[]

}

 

Appreciate all your input.

Thanks,

Enrique

 

1 ACCEPTED SOLUTION

ARG645
Tera Guru

Your almost there..small changes in your script here and there..

var filter =[];//array in which all the valid Sys_id exist

for(var i = 0; i < updated_users.length; ++i){
var found = false;

var grNew = new GlideRecord('sys_user');
grNew.addQuery('sys_id', updated_users[i]);
grNew.query();
while (grNew.next()){
found = true;

}
if (found == true){//if you find a match, then push it to the filter array
  filter.push(updated_users[i]);
}

current.u_alternates = filter.toString();//set the filterarray values to the list

}//end of for loop

Thank you,

Aman Gurram

View solution in original post

3 REPLIES 3

Ajaykumar1
Tera Guru

Hi,

Please refer the community thread Removing value from list field via business rule

Regards,
Ajay

ARG645
Tera Guru

Your almost there..small changes in your script here and there..

var filter =[];//array in which all the valid Sys_id exist

for(var i = 0; i < updated_users.length; ++i){
var found = false;

var grNew = new GlideRecord('sys_user');
grNew.addQuery('sys_id', updated_users[i]);
grNew.query();
while (grNew.next()){
found = true;

}
if (found == true){//if you find a match, then push it to the filter array
  filter.push(updated_users[i]);
}

current.u_alternates = filter.toString();//set the filterarray values to the list

}//end of for loop

Thank you,

Aman Gurram

Thank you Ajaykumar and Aman for your input.

 

Enrique