<?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 addQuery and addEncodedQuery queries not working correctly. in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/addquery-and-addencodedquery-queries-not-working-correctly/m-p/2042987#M699913</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am having problems getting my addQuery or addEncodedQuery statements work correctly. I am trying to provide a summary of answered options/variables from the Request Item catalog form. &amp;nbsp; But I want to remove all the 'null', false, undefined, [blank], along with some specific options/variables from being listed out in the Task 'Description' field. I created queries using the ServiceNow list query builder, so hopefully, they are correct. &amp;nbsp; I found one article saying to have addEncodedQuery before addQuery but didn't seem to help much. &amp;nbsp; Can you assist me my code or logic in how I am trying filter out unwanted catalog options/variables?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt;var fltr1 = "item_option_newNOT LIKEMembers^ORitem_option_new=NULL^item_option_newNOT LIKEINCORRECT^ORitem_option_new=NULL"; &lt;SPAN style="color: #505050;"&gt; // Filter 'item_option_new' of "Members" and "INCORRECT"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt;var fltr2 = 'value!=false^ORvalue=NULL^value!=undefined^ORvalue=NULL'; &amp;nbsp; &lt;SPAN style="color: #505050;"&gt;// Filter 'value' for "false" and "undefined"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt;var gr = new GlideRecord('sc_req_item');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt;gr.addQuery('request', current.request.sys_id);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt;gr.query();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt;while(gr.next()) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #505050;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Get Owned Variables for Requested Item and sort by Order&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var ownvar = new GlideRecord('sc_item_option_mtom');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ownvar.addEncodedQuery(fltr1); &amp;nbsp; &lt;SPAN style="color: #e23d39;"&gt;// Breaks command &amp;nbsp; &lt;STRONG&gt;task.description = items;&lt;/STRONG&gt; &amp;nbsp; from working&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39; font-size: 8pt;"&gt;&lt;SPAN style="color: #3a0699; font-size: 10.6667px;"&gt; &amp;nbsp; &amp;nbsp; &lt;SPAN style="color: #505050;"&gt; &amp;nbsp; //ownvar.addEncodedQuery(fltr2); &lt;/SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.6667px; color: #e23d39;"&gt;// Breaks command &amp;nbsp; &lt;STRONG&gt;task.description = items;&lt;/STRONG&gt; &amp;nbsp; from working&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ownvar.addQuery('request_item.number', gr.number);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #505050;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //ownvar.addQuery('sc_item_option.value','!=',''); &amp;nbsp; &lt;SPAN style="color: #2873ee;"&gt;// Doesn't seem to filter anything&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ownvar.addQuery('sc_item_option.value','!=','false'); &lt;SPAN style="color: #7ed529;"&gt; // Removes all 'false' options/variables (blank) - works&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ownvar.addQuery('sc_item_option.value','!=','undefined'); &lt;SPAN style="color: #e23d39;"&gt;// Must have this line to work, not sure why, but when REMARKED out it breaks?&lt;SPAN style="color: #7ed529;"&gt; -works&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #505050;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //ownvar.addQuery('sc_item_option.item_option_new.name','!*','Members'); &amp;nbsp; &lt;SPAN style="color: #e23d39;"&gt;// Doesn't work&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #505050;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //ownvar.addNotNullQuery('sc_item_option.value'); &amp;nbsp; &lt;SPAN style="color: #2873ee; font-size: 10.6667px;"&gt;// Doesn't seem to filter anything but seems logical to use.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ownvar.orderBy('sc_item_option.order');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ownvar.query();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var items = "Summary of " + gr.number + ": &amp;nbsp; " + gr.cat_item.getDisplayValue() + "\n\n";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; while(ownvar.next()) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var field = ownvar.sc_item_option.item_option_new;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var fieldValue = ownvar.sc_item_option.item_option_new.name;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #505050;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Print variable name&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; items += field.getDisplayValue() + ": &amp;nbsp; " + gr.variables[fieldValue].getDisplayValue() + "\n";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt;task.description = items;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; color: #303030;"&gt;Thank you,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; color: #303030;"&gt;-Wesley&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Dec 2017 21:17:22 GMT</pubDate>
    <dc:creator>Wesley Breshear</dc:creator>
    <dc:date>2017-12-28T21:17:22Z</dc:date>
    <item>
      <title>addQuery and addEncodedQuery queries not working correctly.</title>
      <link>https://www.servicenow.com/community/developer-forum/addquery-and-addencodedquery-queries-not-working-correctly/m-p/2042987#M699913</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am having problems getting my addQuery or addEncodedQuery statements work correctly. I am trying to provide a summary of answered options/variables from the Request Item catalog form. &amp;nbsp; But I want to remove all the 'null', false, undefined, [blank], along with some specific options/variables from being listed out in the Task 'Description' field. I created queries using the ServiceNow list query builder, so hopefully, they are correct. &amp;nbsp; I found one article saying to have addEncodedQuery before addQuery but didn't seem to help much. &amp;nbsp; Can you assist me my code or logic in how I am trying filter out unwanted catalog options/variables?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt;var fltr1 = "item_option_newNOT LIKEMembers^ORitem_option_new=NULL^item_option_newNOT LIKEINCORRECT^ORitem_option_new=NULL"; &lt;SPAN style="color: #505050;"&gt; // Filter 'item_option_new' of "Members" and "INCORRECT"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt;var fltr2 = 'value!=false^ORvalue=NULL^value!=undefined^ORvalue=NULL'; &amp;nbsp; &lt;SPAN style="color: #505050;"&gt;// Filter 'value' for "false" and "undefined"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt;var gr = new GlideRecord('sc_req_item');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt;gr.addQuery('request', current.request.sys_id);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt;gr.query();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt;while(gr.next()) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #505050;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Get Owned Variables for Requested Item and sort by Order&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var ownvar = new GlideRecord('sc_item_option_mtom');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ownvar.addEncodedQuery(fltr1); &amp;nbsp; &lt;SPAN style="color: #e23d39;"&gt;// Breaks command &amp;nbsp; &lt;STRONG&gt;task.description = items;&lt;/STRONG&gt; &amp;nbsp; from working&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39; font-size: 8pt;"&gt;&lt;SPAN style="color: #3a0699; font-size: 10.6667px;"&gt; &amp;nbsp; &amp;nbsp; &lt;SPAN style="color: #505050;"&gt; &amp;nbsp; //ownvar.addEncodedQuery(fltr2); &lt;/SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.6667px; color: #e23d39;"&gt;// Breaks command &amp;nbsp; &lt;STRONG&gt;task.description = items;&lt;/STRONG&gt; &amp;nbsp; from working&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ownvar.addQuery('request_item.number', gr.number);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #505050;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //ownvar.addQuery('sc_item_option.value','!=',''); &amp;nbsp; &lt;SPAN style="color: #2873ee;"&gt;// Doesn't seem to filter anything&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ownvar.addQuery('sc_item_option.value','!=','false'); &lt;SPAN style="color: #7ed529;"&gt; // Removes all 'false' options/variables (blank) - works&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ownvar.addQuery('sc_item_option.value','!=','undefined'); &lt;SPAN style="color: #e23d39;"&gt;// Must have this line to work, not sure why, but when REMARKED out it breaks?&lt;SPAN style="color: #7ed529;"&gt; -works&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #505050;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //ownvar.addQuery('sc_item_option.item_option_new.name','!*','Members'); &amp;nbsp; &lt;SPAN style="color: #e23d39;"&gt;// Doesn't work&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #505050;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //ownvar.addNotNullQuery('sc_item_option.value'); &amp;nbsp; &lt;SPAN style="color: #2873ee; font-size: 10.6667px;"&gt;// Doesn't seem to filter anything but seems logical to use.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ownvar.orderBy('sc_item_option.order');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ownvar.query();&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var items = "Summary of " + gr.number + ": &amp;nbsp; " + gr.cat_item.getDisplayValue() + "\n\n";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; while(ownvar.next()) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var field = ownvar.sc_item_option.item_option_new;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var fieldValue = ownvar.sc_item_option.item_option_new.name;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #505050;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Print variable name&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; items += field.getDisplayValue() + ": &amp;nbsp; " + gr.variables[fieldValue].getDisplayValue() + "\n";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #3a0699;"&gt;task.description = items;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; color: #303030;"&gt;Thank you,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; color: #303030;"&gt;-Wesley&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2017 21:17:22 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/addquery-and-addencodedquery-queries-not-working-correctly/m-p/2042987#M699913</guid>
      <dc:creator>Wesley Breshear</dc:creator>
      <dc:date>2017-12-28T21:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: addQuery and addEncodedQuery queries not working correctly.</title>
      <link>https://www.servicenow.com/community/developer-forum/addquery-and-addencodedquery-queries-not-working-correctly/m-p/2042988#M699914</link>
      <description>&lt;P class="p1"&gt;Hello Wesley,&lt;BR /&gt; &lt;/P&gt;&lt;BR /&gt;&lt;P class="p1"&gt;There is a lot going on in this code.&lt;BR /&gt; &lt;/P&gt;&lt;BR /&gt;&lt;P class="p1"&gt;For starters try this:&lt;/P&gt;&lt;BR /&gt;&lt;P class="p1"&gt;currently you are declaring your variable Items inside a while loop, and then trying to access it outside of that while loop. &amp;nbsp; I would not expect this to ever work, encoded query or not. &amp;nbsp; On line 1 declare&lt;/P&gt;&lt;BR /&gt;&lt;P class="p2"&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P class="p1"&gt;var items = '';&lt;/P&gt;&lt;BR /&gt;&lt;P class="p2"&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P class="p1"&gt;There are 3 layers outside code, while loop 1, while loop 2.&lt;SPAN class="Apple-converted-space"&gt; &amp;nbsp; &lt;/SPAN&gt;You define items in while loop 1, add to it in while loop 2, then try to access it in the outside code. &lt;SPAN class="Apple-converted-space"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P class="p2"&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P class="p1"&gt;Next you might want to consider cleaning up this code.&lt;SPAN class="Apple-converted-space"&gt; &amp;nbsp; &lt;/SPAN&gt;You have a ton of queries that can all be lumped into a single encoded query string.&lt;/P&gt;&lt;BR /&gt;&lt;P class="p2"&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P class="p1"&gt;Does that help?&lt;/P&gt;&lt;BR /&gt;&lt;P class="p2"&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P class="p1"&gt;Best,&lt;/P&gt;&lt;BR /&gt;&lt;P class="p1"&gt;Andrew&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 03 Jan 2018 15:29:21 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/addquery-and-addencodedquery-queries-not-working-correctly/m-p/2042988#M699914</guid>
      <dc:creator>Andrew Wortham</dc:creator>
      <dc:date>2018-01-03T15:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: addQuery and addEncodedQuery queries not working correctly.</title>
      <link>https://www.servicenow.com/community/developer-forum/addquery-and-addencodedquery-queries-not-working-correctly/m-p/2042989#M699915</link>
      <description>&lt;P&gt;Hi Andrew,&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Yes, that is the goal to get the encoded query to have all the queries. &amp;nbsp; But my encoded wasn't working. &amp;nbsp; I am using the code from another community string and it works perfect but I am needing to filter out some additional fields (I am still learning JavaScript). &amp;nbsp; I see your point about the VARs being inside the other loops but it seems fine and it is how the list of options gets created. &amp;nbsp; I was hoping something would pop-out with my encoded queries not having the correct syntax.&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;I think that I figure out what I was doing wrong but still doing some testing to validate my changes. &amp;nbsp; When I built the query it was using 'display value' and it looks using 'value' is working now. &amp;nbsp; Also, do you know how I can reduce or clean up this code? &amp;nbsp; All the addQuery's?&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;var fltr1 = "sc_item_option.item_option_new.nameNOT LIKEu_subscription_users"; &lt;SPAN style="color: #7ed529;"&gt; // This seems to be working now, using value vs. display value&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;var gr = new GlideRecord('sc_req_item');&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;gr.addQuery('request', current.request.sys_id);&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;gr.query();&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt; &amp;nbsp; while(gr.next()) {&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #2873ee;"&gt; &amp;nbsp; // Get Owned Variables for Requested Item and sort by Order&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt; &amp;nbsp; var ownvar = new GlideRecord('sc_item_option_mtom');&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt; &amp;nbsp; ownvar.addEncodedQuery(fltr1); &amp;nbsp; &lt;SPAN style="color: #7ed529; font-size: 10.6667px;"&gt;// This seems to be working now&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt; &amp;nbsp; ownvar.addQuery('request_item.number', gr.number);&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt; &amp;nbsp; ownvar.addQuery('sc_item_option.value', '!=', ''); &amp;nbsp; &lt;SPAN style="color: #2873ee;"&gt;// Doesn't seem to filter anything&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt; &amp;nbsp; ownvar.addQuery('sc_item_option.value', '!=', 'false'); &amp;nbsp; &lt;SPAN style="color: #2873ee;"&gt;// Removes all 'false' variables (blank)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt; &amp;nbsp; ownvar.addQuery('sc_item_option.value', '!=', 'undefined');&lt;SPAN style="color: #e23d39;"&gt; // Must have this line to work not sure why but when REMARKED out it breaks&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt; &amp;nbsp; ownvar.addNotNullQuery('sc_item_option.value'); &lt;SPAN style="color: #eb7a3d;"&gt; // Not sure if this is needed or helping.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt; &amp;nbsp; ownvar.orderBy('sc_item_option.order');&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt; &amp;nbsp; ownvar.query();&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt; &amp;nbsp; var items = "Summary of " + gr.number + ": &amp;nbsp; " + gr.cat_item.getDisplayValue() + "\n\n";&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; while(ownvar.next()) {&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; var field = ownvar.sc_item_option.item_option_new;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; var fieldValue = ownvar.sc_item_option.item_option_new.name;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; color: #2873ee;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Print variable name and option value&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; items += field.getDisplayValue() + ": &amp;nbsp; " + gr.variables[fieldValue].getDisplayValue() + "\n";&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;task.description = items;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;-Wesley&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 04 Jan 2018 23:48:46 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/addquery-and-addencodedquery-queries-not-working-correctly/m-p/2042989#M699915</guid>
      <dc:creator>Wesley Breshear</dc:creator>
      <dc:date>2018-01-04T23:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: addQuery and addEncodedQuery queries not working correctly.</title>
      <link>https://www.servicenow.com/community/developer-forum/addquery-and-addencodedquery-queries-not-working-correctly/m-p/2042990#M699916</link>
      <description>&lt;P&gt;Remove all queries and just use this&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 8pt; font-family: inherit;"&gt;var gr = new GlideRecord('sc_req_item');&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 8pt; font-family: inherit;"&gt;gr.addQuery('request', current.request.sys_id);&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 8pt; font-family: inherit;"&gt;gr.query();&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 8pt; font-family: inherit;"&gt; &amp;nbsp; while(gr.next()) {&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 8pt; font-family: inherit; color: #2873ee;"&gt; &amp;nbsp; // Get Owned Variables for Requested Item and sort by Order&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 8pt; font-family: inherit;"&gt; &amp;nbsp; var ownvar = new GlideRecord('sc_item_option_mtom');&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;SPAN style="color: #666666; font-family: arial, sans-serif; font-size: 10.6667px;"&gt; &amp;nbsp; ownvar.addEncodedQuery(&lt;/SPAN&gt;'sc_item_option.valueISNOTEMPTY^sc_item_option.value!=false^sc_item_option.value!=undefined^request_item='+gr.sys_id+'^sc_item_option.sc_cat_item_option.nameNOT LIKEu_subscription_users');&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 8pt; font-family: inherit;"&gt; &amp;nbsp; ownvar.orderBy('sc_item_option.order');&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 8pt; font-family: inherit;"&gt; &amp;nbsp; ownvar.query();&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 8pt; font-family: inherit;"&gt; &amp;nbsp; var items = "Summary of " + gr.number + ": &amp;nbsp; " + gr.cat_item.getDisplayValue() + "\n\n";&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 8pt; font-family: inherit;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; while(ownvar.next()) {&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 8pt; font-family: inherit;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; var field = ownvar.sc_item_option.item_option_new;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 8pt; font-family: inherit;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; var fieldValue = ownvar.sc_item_option.item_option_new.name;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 8pt; font-family: inherit; color: #2873ee;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Print variable name and option value&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 8pt; font-family: inherit;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; items += field.getDisplayValue() + ": &amp;nbsp; " + gr.variables[fieldValue].getDisplayValue() + "\n";&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 8pt; font-family: inherit;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 8pt; font-family: inherit;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P style="font-family: arial, sans-serif; color: #666666;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 8pt; font-family: inherit;"&gt;task.description = items;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 05 Jan 2018 00:42:10 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/addquery-and-addencodedquery-queries-not-working-correctly/m-p/2042990#M699916</guid>
      <dc:creator>SanjivMeher</dc:creator>
      <dc:date>2018-01-05T00:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: addQuery and addEncodedQuery queries not working correctly.</title>
      <link>https://www.servicenow.com/community/developer-forum/addquery-and-addencodedquery-queries-not-working-correctly/m-p/2042991#M699917</link>
      <description>&lt;P&gt;Please see below for how to troubleshoot and successfully build encoded queries:&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;OL&gt;&lt;LI&gt;Look at the Dictionary Entry for your table to get the the field labels and names&lt;span class="lia-inline-image-display-wrapper" image-alt="find_real_file.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/66134i09C65896F945D642/image-size/large?v=v2&amp;amp;px=999" role="button" title="find_real_file.png" alt="find_real_file.png" /&gt;&lt;/span&gt;&lt;/LI&gt;&lt;LI&gt;Build the filter in ServiceNow&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="find_real_file.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/66142iEDB9889C1300CB16/image-size/large?v=v2&amp;amp;px=999" role="button" title="find_real_file.png" alt="find_real_file.png" /&gt;&lt;/span&gt;&lt;/LI&gt;&lt;LI&gt;Modify the filter until it returns the result set you want&lt;/LI&gt;&lt;LI&gt;Copy the query from the filter breadcrumb&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="find_real_file.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/66132i22B7019F8054033F/image-size/large?v=v2&amp;amp;px=999" role="button" title="find_real_file.png" alt="find_real_file.png" /&gt;&lt;/span&gt;&lt;/LI&gt;&lt;LI&gt;Copy it into your code (example)&lt;/LI&gt;&lt;/OL&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="_jivemacro_uid_15151163422721584 jive_macro_code jive_text_macro" data-renderedposition="1472.78125_8_1192_32" jivemacro_uid="_15151163422721584"&gt;&lt;P&gt;var encQry = 'sc_item_option.valueISNOTEMPTY^sc_item_option.value!=false^sc_item_option.value!=undefined^request_item.cat_item=0241d1b2db4e4700821a3e5c7c9619b8';&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;gr.addEncodedQuery(encQry );&lt;/P&gt;&lt;BR /&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Jan 2018 01:39:44 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/addquery-and-addencodedquery-queries-not-working-correctly/m-p/2042991#M699917</guid>
      <dc:creator>paulmorris</dc:creator>
      <dc:date>2018-01-05T01:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: addQuery and addEncodedQuery queries not working correctly.</title>
      <link>https://www.servicenow.com/community/developer-forum/addquery-and-addencodedquery-queries-not-working-correctly/m-p/2042992#M699918</link>
      <description>&lt;P&gt;Hello Wesley,&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;+1 to what Paul said, build out the query see the resulting records, and then when correct "copy query"&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Is the issue you are running into an actual error? &amp;nbsp; Or are you just not getting any results back?&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;When you "addEncodedQuery" just like when you "addQuery" it is going to add an and clause to the GlideRecord this means that you encoded query and every other query has to return true in order to be returned. &amp;nbsp; Sometimes you will end up conflicting queries when you have such a complex GlideRecord, which is why I tend to prefer a single encoded query. &amp;nbsp; &lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;Andrew&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 05 Jan 2018 19:16:28 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/addquery-and-addencodedquery-queries-not-working-correctly/m-p/2042992#M699918</guid>
      <dc:creator>Andrew Wortham</dc:creator>
      <dc:date>2018-01-05T19:16:28Z</dc:date>
    </item>
  </channel>
</rss>

