Reuse a list filter in a script with addEncodedQuery()
Build complex filters in the list view, copy the encoded query, and use it in scripts safely, with a quick check that the query is valid.
October 1, 2026 · #encoded-query #gliderecord #productivity
Writing encoded queries by hand invites typos. Build the filter in a list, then right-click the breadcrumb and choose Copy query.
var QUERY = 'active=true^priority=1^ORpriority=2^assignment_groupISEMPTY';
var gr = new GlideRecord('incident');
gr.addEncodedQuery(QUERY);
// A field name typo makes the platform drop that condition and match more
// records than you expect. Check the query before relying on it.
if (!gr.isValidEncodedQuery(QUERY)) {
gs.warn('Encoded query is not valid for this table: ' + QUERY);
} else {
gr.setLimit(20);
gr.query();
while (gr.next()) {
gs.info(gr.getValue('number') + ' · ' + gr.getDisplayValue('priority'));
}
}
How it works
addEncodedQuery()accepts exactly what the list filter produces, including^ORand^NQgroups.isValidEncodedQuery()catches field names that don’t exist on the table.
Gotchas
- Copied queries can contain sys_ids specific to one instance (assignment groups, users). Swap those for properties before moving code between instances.
- Date conditions copied from lists use
javascript:gs.…helpers; they run server-side, which is fine in scripts.
MIT licence. Provided as-is, without warranty. Test in a sub-production instance first.