<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Is there a hard limit on the size of EncodedQuery in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/is-there-a-hard-limit-on-the-size-of-encodedquery/m-p/3572267#M1259918</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/789495"&gt;@patrikturc&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;For ServiceNow, there is &lt;STRONG&gt;no commonly documented hard limit specifically on GlideRecord.addEncodedQuery()&lt;/STRONG&gt;, but in practice a &lt;STRONG&gt;700,000-character encoded query is not a good approach&lt;/STRONG&gt; and will likely hit platform, database limitations long before it becomes efficient.&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;H4&gt;Option 1 : Use IN instead of thousands of ^NQ&lt;/H4&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;LI-CODE lang="markup"&gt;var ids = [];

while (sourceGR.next()) {
    ids.push(sourceGR.getUniqueValue());
}

var targetGR = new GlideRecord('target_table');
targetGR.addQuery('parent', 'IN', ids.join(','));
targetGR.query();&lt;/LI-CODE&gt;&lt;DIV&gt;Option 2: Batch the query&lt;/DIV&gt;&lt;LI-CODE lang="markup"&gt;var batchSize = 500;

for (var i = 0; i &amp;lt; ids.length; i += batchSize) {
    var batch = ids.slice(i, i + batchSize);

    var gr = new GlideRecord('target_table');
    gr.addQuery('parent', 'IN', batch.join(','));
    gr.query();

    while (gr.next()) {
        // process records
    }
}&lt;/LI-CODE&gt;&lt;P&gt;if you find the solution helpful please mark it helpful and accept the solution.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;STRONG&gt;Sagnic&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 11 Jul 2026 20:11:13 GMT</pubDate>
    <dc:creator>Its_Sagnic</dc:creator>
    <dc:date>2026-07-11T20:11:13Z</dc:date>
    <item>
      <title>Is there a hard limit on the size of EncodedQuery</title>
      <link>https://www.servicenow.com/community/developer-forum/is-there-a-hard-limit-on-the-size-of-encodedquery/m-p/3571917#M1259884</link>
      <description>&lt;P&gt;I would like to find out when using .addEncodedQuery('&lt;STRONG&gt;Is there a char limit here?'&lt;/STRONG&gt;).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to limit the number of database calls by building a large encoded query and then making a single call that returns all items. Basically, instead of having a query call for each result of the previous query in a while loop, we loop through the initial result and build a large encoded query using ^NQ blocks for each of the query results.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's say this results in encodedQuery of roughly 700k characters called once. Instead of making 7000 short db queries.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jul 2026 14:12:01 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/is-there-a-hard-limit-on-the-size-of-encodedquery/m-p/3571917#M1259884</guid>
      <dc:creator>patrikturc</dc:creator>
      <dc:date>2026-07-10T14:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a hard limit on the size of EncodedQuery</title>
      <link>https://www.servicenow.com/community/developer-forum/is-there-a-hard-limit-on-the-size-of-encodedquery/m-p/3572066#M1259894</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;If the encoded query is being passed via a URL (list views, GlideAjax, REST API), browsers and web servers enforce URL length limits — typically around 8,000 characters.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;There is&amp;nbsp; no published char limit for Glide query but 700k characters with 7000 ^NQ blocks will almost certainly time out or fail silently. Switch to IN with chunking — same goal of reducing db calls, far more reliable at scale.&lt;BR /&gt;&lt;BR /&gt;Can you share your query?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jul 2026 22:47:40 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/is-there-a-hard-limit-on-the-size-of-encodedquery/m-p/3572066#M1259894</guid>
      <dc:creator>Aanchal Agarwa1</dc:creator>
      <dc:date>2026-07-10T22:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a hard limit on the size of EncodedQuery</title>
      <link>https://www.servicenow.com/community/developer-forum/is-there-a-hard-limit-on-the-size-of-encodedquery/m-p/3572267#M1259918</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/789495"&gt;@patrikturc&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;For ServiceNow, there is &lt;STRONG&gt;no commonly documented hard limit specifically on GlideRecord.addEncodedQuery()&lt;/STRONG&gt;, but in practice a &lt;STRONG&gt;700,000-character encoded query is not a good approach&lt;/STRONG&gt; and will likely hit platform, database limitations long before it becomes efficient.&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;H4&gt;Option 1 : Use IN instead of thousands of ^NQ&lt;/H4&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;LI-CODE lang="markup"&gt;var ids = [];

while (sourceGR.next()) {
    ids.push(sourceGR.getUniqueValue());
}

var targetGR = new GlideRecord('target_table');
targetGR.addQuery('parent', 'IN', ids.join(','));
targetGR.query();&lt;/LI-CODE&gt;&lt;DIV&gt;Option 2: Batch the query&lt;/DIV&gt;&lt;LI-CODE lang="markup"&gt;var batchSize = 500;

for (var i = 0; i &amp;lt; ids.length; i += batchSize) {
    var batch = ids.slice(i, i + batchSize);

    var gr = new GlideRecord('target_table');
    gr.addQuery('parent', 'IN', batch.join(','));
    gr.query();

    while (gr.next()) {
        // process records
    }
}&lt;/LI-CODE&gt;&lt;P&gt;if you find the solution helpful please mark it helpful and accept the solution.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;STRONG&gt;Sagnic&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jul 2026 20:11:13 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/is-there-a-hard-limit-on-the-size-of-encodedquery/m-p/3572267#M1259918</guid>
      <dc:creator>Its_Sagnic</dc:creator>
      <dc:date>2026-07-11T20:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a hard limit on the size of EncodedQuery</title>
      <link>https://www.servicenow.com/community/developer-forum/is-there-a-hard-limit-on-the-size-of-encodedquery/m-p/3572308#M1259931</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/789495"&gt;@patrikturc&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;There is no specific a query limit mentioned in ServiceNow Documentation.&lt;/P&gt;&lt;P&gt;As a best practice, it's recommended to process large volumes of data in batches or chunks. This approach helps improve system performance, reduces the risk of long-running transactions, and minimizes the impact on overall platform stability.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Please follow below thread :&amp;nbsp;&lt;A href="https://www.servicenow.com/community/developer-forum/what-is-the-max-query-string-length-can-be-passed-to-default/m-p/2651201" target="_blank"&gt;https://www.servicenow.com/community/developer-forum/what-is-the-max-query-string-length-can-be-passed-to-default/m-p/2651201&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Please mark helpful &amp;amp; correct answer if it's worthy for you.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Jul 2026 04:58:44 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/is-there-a-hard-limit-on-the-size-of-encodedquery/m-p/3572308#M1259931</guid>
      <dc:creator>abirakundu23</dc:creator>
      <dc:date>2026-07-12T04:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a hard limit on the size of EncodedQuery</title>
      <link>https://www.servicenow.com/community/developer-forum/is-there-a-hard-limit-on-the-size-of-encodedquery/m-p/3572680#M1260024</link>
      <description>&lt;P class=""&gt;&lt;STRONG&gt;Thank you all for the very helpful answers - ServiceNow provided very similar guidance. I've now completed testing with the suggested approaches.&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;To my surprise, the &lt;STRONG&gt;700k-character query&lt;/STRONG&gt; completed successfully, although it took &lt;STRONG&gt;29 seconds&lt;/STRONG&gt; to run. Batching the query reduced the execution time to ~&lt;STRONG&gt;8 seconds&lt;/STRONG&gt;.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;After changing the logic to use &lt;STRONG&gt;IN&amp;nbsp;&lt;/STRONG&gt;instead, the runtime dropped further to around &lt;STRONG&gt;2.2 seconds&lt;/STRONG&gt;. Batching produced a similar runtime in this case, although it would likely be the more future-proof approach.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jul 2026 10:06:47 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/is-there-a-hard-limit-on-the-size-of-encodedquery/m-p/3572680#M1260024</guid>
      <dc:creator>patrikturc</dc:creator>
      <dc:date>2026-07-13T10:06:47Z</dc:date>
    </item>
  </channel>
</rss>

