How to get input.variables values to an another list in action script servicenow

SSA1
Giga Expert

Hi,

I have action script in servicenow flow designer.

There from the UI there's a list collector, it inputs list of team members names,

So when in action script i need to get each of them separately to an array or list.

Later i should be able to access these each element one by one.

I have tried this code but it's not working as expected.

  var completed=[];
  var user_list=[];
  var vaccinated=[];
  var not_vaccinated=[];
 var user_list=inputs.team_members;
 
  
  for(var i=0; i < user_list.length; i++){
   
    var gr_vacc_state=new GlideRecord('v_status');
    gr_vacc_state.addQuery('u_employee_name',user_list[i]);
    gr_vacc_state.addQuery('u_vaccination_status','vaccinated');
    gr_vacc_state.query();
      
    if(gr_vacc_state.next()){
        if(completed==null)
            {
             	
              completed.push(user_list[i]);
            }
          else
          	{
          		
              completed.push(user_list[i]);
         	}
           vaccinated.push(user_list[i]);
        }
      	else
        {
           not_vaccinated.push(user_list[i]);
        }
    }
  
   outputs.vaccinated=completed;
  outputs.not_vaccinated=not_vaccinated;

 

output shows like this, even output is not correct

find_real_file.png

 

My question is how to get each team member's sys_id separately to a list or array, from inputs.team_members list collector in action script.

1 ACCEPTED SOLUTION

palanikumar
Mega Sage

Hi,

List collector returns comma separated string of sys_id's. You need to split it to iterate in for loop.

Replace the line var user_list=inputs.team_members; with the below script and see whether your issue is fixed

var user_list=inputs.team_members.split(',');

Thank you,
Palani

View solution in original post

1 REPLY 1

palanikumar
Mega Sage

Hi,

List collector returns comma separated string of sys_id's. You need to split it to iterate in for loop.

Replace the line var user_list=inputs.team_members; with the below script and see whether your issue is fixed

var user_list=inputs.team_members.split(',');

Thank you,
Palani