AddQuery vs AddEncodedQuery
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 03:19 AM
Hi All,
Is there a difference between addquery and addencodedquery. Is there a performance difference between these two considering 2 scenarios : a) When only column value is being matched b)When multiple column values are being matched?
Eventually the query gets converted to "Select *" format right ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 06:42 AM
So far zero responses regarding any performance difference.
Personally would also not expect so, than that would already be known.
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 06:35 AM
HI @Anubhav24 ,
I trust you are doing great.
Performance Difference:
a) When only column value is being matched: There's no significant performance difference between addQuery and addEncodedQuery when filtering by a single column value. Both methods will generate efficient SQL queries behind the scenes.
b) When multiple column values are being matched: Again, there's no substantial performance difference between the two methods. However, addEncodedQuery might be more concise for complex queries with multiple conditions.
SQL Conversion:
Yes, behind the scenes, ServiceNow translates these GlideRecord queries into SQL queries. For instance, a GlideRecord query on the 'incident' table might be translated to something like:
SELECT * FROM incident WHERE priority = 1 AND state = 2;
However, it's worth noting that ServiceNow abstracts this SQL layer for security and efficiency reasons, so developers work with the GlideRecord API instead of direct SQL.
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi