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

Interesting, this property only works with addQuery().   It does not work with get(), which makes sense, but I thought I'd point it out.


Does it work with addEncodedQuery?


The property does work with addEncodedQuery().



So yes to addQuery() and addEncodedQuery(), but no to get().


Mike Allen
Mega Sage

I am guessing that fooBar and sillyWilly are not, in fact, fields on the form.   I tried with incident and fake fields:


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


    <g:evaluate>  


            var bcc = new GlideRecord('incident');  


            bcc.get('u_frdea', gs.getUserID());


      gs.log(bcc.sys_id, '$$$$ - bcc');


    </g:evaluate>  


    <g:evaluate>  


              var erc = new GlideRecord('incident');  


              erc.get('u_hakldj', gs.getUserID());


      gs.log(erc.sys_id, '$$$$ - erc');


      </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>



It returns the sys_id of the first incident in the list.   This leads me to believe that if you populate an addQuery with a false field, the GlideRecord query will ignore that condition.


Your last sentence hits the nail on the head.   This is true, but ServiceNow should not allow this.