List Collector values Dot Walking

Anubhav24
Mega Sage
Mega Sage

Hi All,

 

I am working on obtaining the values from a list collector and once I split and obtain the individual values by looping through the individual values. I have two queries:

1)What is the most efficient way to loop through all values.

2)Once we have the individual sys_ids , can we dot walk them and obtain other values or is dot walking not possible when sys_ids are retrieved from list collector.

 

 

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@Anubhav24 

it depends on where are you doing this operation?

1) if in flow then you can use FOR Each to iterate over

See this on how you can iterate easily using Flow

list collector iterate.gif

OR

2) if you are doing in workflow then only option is to use Run Script

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

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

Yes I am doing it in a Script Include , in that case is splitting and then iterating through the values is the most efficient way ? Also could you please let me know on the second point ?

@Anubhav24 

the 2nd point talks about scripting only.

The 1st point is valid and has approach when you are using flow

In scripting you are on right track

1) get the value, split it with comma

2) you get the array

3) then you can iterate and perform GlideRecord query to get whatever field value you want

Another way without split is this -> use IN in the addQuery with sysId

var listCollectorValues = current.variables.listCollectorVariableName.toString();
var gr = new GlideRecord("tableName");
gr.addQuery("sys_id", "IN", listCollectorValues);
gr.query();
while (gr.next()) {
    gs.info(gr.fieldName);
}

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

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

@Ankur Bawiskar   There is one more point in the second query , can we dot walk using the sys_ids received from list collector ? like if we have a reference field for a sys_user table and we dot walk to the fields on sys_user table , similarly if we have a list collector of multiple users can we also dot walk or no ?