- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2022 08:49 AM
Let's say I create a new GR and then perform a query on it like so:
var gr1 = new GlideRecord('table');
gr1.addQuery('x', y);
gr1.query();
I want to then store the results of this query in a new object, and then perform more queries on that object instead of querying gr1 again. I want to do this because I want to keep the results in gr1 intact, and then use other objects to further filter down the results if possible.
How can I do this?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2022 09:35 AM
Hi,
You can try this way
var records = "";
var gr1 = new GlideRecord('table');
gr1.addQuery('x', y);
gr1.query();
while(gr1.next())
{
records = records + gr1.sys_id + ",";
}
var encodedquery = "sys_idIN"+records;
//now you can use the above encoded query in other gliderecords
//for example
var gr2 = new GlideRecord('table');
gr2.addEncodedQuery(encodedquery);
gr2.query();
Mark as correct and helpful if it solved your query.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2022 09:05 AM
gr1.query() is what finally goes to the database and does the thing.
You won't be able to avoid a second query()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2022 09:35 AM
Hi,
You can try this way
var records = "";
var gr1 = new GlideRecord('table');
gr1.addQuery('x', y);
gr1.query();
while(gr1.next())
{
records = records + gr1.sys_id + ",";
}
var encodedquery = "sys_idIN"+records;
//now you can use the above encoded query in other gliderecords
//for example
var gr2 = new GlideRecord('table');
gr2.addEncodedQuery(encodedquery);
gr2.query();
Mark as correct and helpful if it solved your query.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2022 10:53 AM
Thank you! I like your approach and it seems to do what I need