The Zurich release has arrived! Interested in new features and functionalities? Click here for more

what is the difference between add query and add encoded query?

rajaa
Giga Contributor

o

5 REPLIES 5

Shishir Srivast
Mega Sage

using addQuery() you can give filter based upon the one field,


using addEncodedQuery() you can filter the record based upon the multiple fileds (you can copy the breadcrumb string and use as it is in encoded query under quotes).



find_real_file.png


For More details: GlideRecord - Global


Harsh Vardhan
Giga Patron

addEncodedQuery() : you can deine multiple filter here under the one string.


addQuery(): it will basically does the same but you can only able to put one filter condition here..



Note: both used to filter out the result.


Harsh Vardhan
Giga Patron

Hi



Adding another link will give you more understanding about addQuery() and addEncodedQuery()



  • While adding filters in GlideRecord queries is good, avoid creating filters which are too complex.

Rather than creating a series of addQuery() and addOrCondition() calls to obtain a result, use addEncodedQuery(). This will make the query easier to create and maintain. Avoid complex queries on very large tables.


Create a query string by generating encoded query strings through a filter and using that string with addEncodedQuery. As an example, if I want all incidents that are active, created after a certain date with a certain state and a particular approval value I go in the instance at incidents module, expand "All" filter and add all my conditions then click "Run". Then right click on the link, "Copy query" and I get my encoded query:


"active=true^sys_created_on>javascript:gs.dateGenerate('2015-09-01','23:59:59')^state=3^approval=requested"





https://bitsofcode.io/servicenow-gliderecord-performance/