query a list of sys ids on a table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2024 07:20 AM
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);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2024 07:38 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2024 07:52 AM
i want to take those sys id and query each sys id in a different table to get their display values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2024 07:56 AM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2024 07:57 AM - edited 09-06-2024 07:58 AM
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