Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Why I am not able to process the list type input inside the action script?

Not applicable

I have a input i.e. list user type where people can select multiple users. 

While I am trying to fetch the mails of the users I am not getting the result? What I am missing here?

a.pngb.png

1 ACCEPTED SOLUTION

@Community Alums 

another way is this

1) that flow action will accept input of type Records

AnkurBawiskar_0-1745236011629.png

 

2) then in script step simply iterate those records

AnkurBawiskar_1-1745236040494.png

 

3) then pass array of records as input to that action from script (I haven't tested it yet)

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

14 REPLIES 14

J Siva
Kilo Patron

Hi @Community Alums 
Input type is String. So you need to convert that into array before iteration.
Try below script. 
Input-> Approver sys ids. Type: String

Output-> Approver email ids. Type:String

Script:

var approverEmail = [];
var approvers = inputs.approver_sysId;
var approver_arr = approvers.split(",");
for (var i = 0; i < approver_arr.length; i++) {
    var user = new GlideRecord("sys_user");
    user.get(approver_arr[i]);
    approverEmail.push(user.email);
}
outputs.approver_emails = approverEmail.toString();

Regards,

Siva

Not applicable

No luck, it is not working.

 

Approver input field type is List referenced to user table where as output is a string only.

Please see the below image how I am giving.

Manikantahere_0-1745225471174.png

 

Ankur Bawiskar
Tera Patron

@Community Alums 

what's the input type for the input variable of script step?

since you are passing list of users, it's an array of objects I believe of GlideRecord

what came in logs?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Not applicable

I don't think I can set the input type for the input variable of script step. but action input type for the approver is List reference to user table.

 

Yes, Its coming as Glide Record object.
But not going into for loop when I executed the script.