The CreatorCon Call for Content is officially open! Get started here.

gliderecord query ignoring addQuery

xiaix
Tera Guru

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

    <g:evaluate>

            var bcc = new GlideRecord('u_bcp_site_departments');

            bcc.addQuery('sillyWilly', gs.getUserID());

            bcc.query();

    </g:evaluate>

    <g:evaluate>

              var erc = new GlideRecord('u_bcp_site_departments');

              erc.addQuery('fooBar', gs.getUserID());

              erc.query();

      </g:evaluate>

      <j:if test="${bcc.next()}">

                      <p>TEST 1</p>

      </j:if>

      <j:if test="${erc.next()}">

                      <p>TEST 2</p>

      </j:if>

</j:jelly>

Odd... I'm seeing both TEST 1 and TEST 2.

I must be missing something simple here.   These should both fail the "<j:if>" test.

1 ACCEPTED SOLUTION

You can add this property 'glide.invalid_query.returns_no_rows' so that the invalid column name query will start returning no rows.


View solution in original post

24 REPLIES 24

I added the following to the sys_properties table:



Screen Shot 10-27-15 at 09.02 AM.JPG



Now... if I set this to "true", it works.   But when I leave it to false but then use gs.getSession().setStrictQuery(true); in my jelly glideRecord query, it doesn't work.   I've logged out and back in, cleared cache, and even reboot the computer.


I *may* have it figured out...



If I set the glide.invalid_query.returns_no_rows value on the sys_properties table to "true", "true" is actually acting like "active".   So, here are my results:


#1


// The sys_properties value to "true"


<g:evaluate>


      gs.getSession().setStrictQuery(true);


      var erc = new GlideRecord('u_bcp_site_departments');


      erc.addQuery('fooBar', gs.getUserID());


      erc.query();


</g:evaluate>



The above code will NOT return any records.. which is perfect.



#2


// The sys_properties value is at "true"


<g:evaluate>


      var erc = new GlideRecord('u_bcp_site_departments');


      erc.addQuery('fooBar', gs.getUserID());


      erc.query();


</g:evaluate>



The above code WILL show all records, even though sys_properties value is "true"



#3


// The sys_properties value is at "true"


<g:evaluate>


      gs.getSession().setStrictQuery(false);


      var erc = new GlideRecord('u_bcp_site_departments');


      erc.addQuery('fooBar', gs.getUserID());


      erc.query();


</g:evaluate>



The above code does in fact show all records.




Conclusion:   So I'm still a bit stumped.   I'm just going to cough it up to a glitch/bug in ServiceNow, and leave the sys_properties value set to "true", and manually override it to false where needed by using:   gs.getSession().setStrictQuery(false);



I'd like to default sys_properties to false and manually override when needed to true, but alas, it's broke.  


You should open a ticket with HI.   Maybe they (being ServiceNow) are unaware and should be informed.


Let me try these things out... Will update the thread back.


Kalaiarasan Pus
Giga Sage

I am not a jelly expert but I added a macro to a catalog and checked this.



Macro


<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


  <g:evaluate var="jvar_sysID" jelly="true">


        var inc = new GlideRecord('incident');


inc.addQuery('sys_idd','12232');


inc.query();


var total=inc.getRowCount();


  total;


</g:evaluate>


  $[jvar_sysID]


</j:jelly>



So I kept changing the property between true and false, but I got the correct result every time. Am I doing something wrong?