query a list of sys ids on a table

ServNowDev
Tera Guru

i have a list of sys_id in a variable called test, test is a set of values that im returning from a script include thats used to filter a reference field so the words sysidIN start the list of values in test.  here is a sample of  values in test . I want to take these sys ids and query each one in another table to get their display names

 

sys_idIN6a9b762197dc5214099bba1de053afaa,0d3bbaed979c5214099bba1de053afe2,1ec43b21971c9214099bba1de053af82
var grCode = new GlideRecord('table_name');
grCode.addQuery('sys_id', 'IN', test.join(','));
grCode.query();

var displayNames = [];
while(grCode.next()){
	displayName.push(grCode.names);
}

  

4 REPLIES 4

Aaron Duncan
Mega Sage

What is the ultimate goal that you're attempting to do? Is it just for the reference field, or is to pull the display values from a different table. More context would help to find a solution.

i want to take those sys id and query each sys id in a different table to get their display values

 

Gangadhar Ravi
Giga Sage
Giga Sage

you can just do something like below 

 

var grCode = new GlideRecord('table_name');
grCode.addEncodedQuery('sys_idIN6a9b762197dc5214099bba1de053afaa,0d3bbaed979c5214099bba1de053afe2,1ec43b21971c9214099bba1de053af82');
grCode.query();
var displayNames = [];
while(grCode.next()){
	displayName.push(grCode.names);
}

they list of sys_ids is mush longer than what i showed, and it will change with each senario so i would not be able to hard code those values