Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

List Collector Reference Dot Walking

ldave
Giga Guru

Is there the possibility to perform dot walking when checking a variable of a ticket, if the variable is a referenced list collector?

 

i.e. if I have a normal reference, i can get the values i need by doing something like:

current.variables.VariableName.ColumnNameOfReferencedTable

 

Is there a way/method to do something like that, maybe in a for loop, for the list collector type?

current.variables.ListoCollectorVariableName[i].ColumnNameOfReferencedTable

 

or the only way would be to split the string and then perform a glide record for each one of the sys_id inside the variable?

 

 

Thank you.

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Dot walking is not possible.  We use something like this to populate a text variable with a comma-separated list of CI Names for each CI selected in a list collector on the cmdb_ci table

var cinamelist = [];
var cis = current.variables.v_ci.toString();//name of your list collector variable
var ci = new GlideRecord('cmdb_ci');//name of your List table
ci.addQuery('sys_id', 'IN', cis);
ci.query();
while(ci.next()){
 cinamelist.push(ci.name);
}
current.variables.v_cinames = cinamelist.join(',');

or you use a for loop on the array of sys_ids

View solution in original post

3 REPLIES 3

Pranesh072
Mega Sage

It is not possible to dot walk because it can contains the multiple records.

 

Yes, you have to do the hard way - the only way would be to split the string and then perform a glide record for each one of the sys_id inside the variable.

 

You can use following query 

     gr.addQuery('sys_id', 'IN', current.getValue('current.variables.ListoCollectorVariableName[i]));

Brad Bowman
Kilo Patron
Kilo Patron

Dot walking is not possible.  We use something like this to populate a text variable with a comma-separated list of CI Names for each CI selected in a list collector on the cmdb_ci table

var cinamelist = [];
var cis = current.variables.v_ci.toString();//name of your list collector variable
var ci = new GlideRecord('cmdb_ci');//name of your List table
ci.addQuery('sys_id', 'IN', cis);
ci.query();
while(ci.next()){
 cinamelist.push(ci.name);
}
current.variables.v_cinames = cinamelist.join(',');

or you use a for loop on the array of sys_ids

ldave
Giga Guru

Thank you, just as I though, I hoped for some magic embedded servicenow method, that's why I asked 🙂

 

Thank you for the prompt answers!!