addActiveQuery() and addEncodedQuery()

nataliya_b
Tera Guru

Hello All

I am running script include function and just notice that

this code lines sequence does not filter for active records

var gr = new GlideRecord(someTable);

gr.addActiveQuery();

gr.addEncodedQuery(strQuery); //

gr.query();

but this one does

var gr = new GlideRecord(someTable);

gr.addEncodedQuery(strQuery);

gr.addActiveQuery();

gr.query();

 

I could not find any docs regarding this 

Does anyone have the same experience? Where could I read about it?

thank you

1 ACCEPTED SOLUTION

Does the encoded query contain an or condition? Or (multiple) layered and conditions?

Then it would matter if the active=true is at the beginning. Or at the end and then part of an or condition for example.

View solution in original post

13 REPLIES 13

Hello Willem

Yes, you right about multiple conditions. I found the cause and fixed it.

thank you for your help!

asifnoor
Kilo Patron

Hi,

Technically if you are using encodedQuery. you need to include active=true within the same encoded query so that the results are filtered accordingly.

Adding encodedquery after addactivequery overrides the encodedquery.

Adding activeQuery at the last gives you results because it applies active=true on the result of the encodedQuery filter.

Mark the comment as a correct answer and helpful if this answers your question.

 

I don't think that's true as my images show the query construct as able to produce the same result. Unless you're referring to when the encoded query has an OR condition? If so, then yes, if the encoded query has an OR, any additional .addQuery / .addActive will only apply to the secondary query

Yes, thats correct and thats that I thought i had typed, but now when i recheck, i noticed that i missed it 🙂

Thanks for pointing it out.