Glide Query OR condition not working as expected.

imran rasheed
Tera Contributor

I am trying to combine the below two add queries with OR condition. Each one works pretty much well individually, but when i am trying it with Encoded OR query or with addOrCondition, it is not working as expected. 

Individual queries:

var RelType = new GlideRecord('task_rel_type');
RelType.addQuery('name', 'Depends on::Dependent for');
RelType.addQuery('name', 'Solved by::Solves');

Tried with encoded query but not working:

//RelType.addEncodedQuery("name=Depends on::Dependent for^ORname=Solved by::Solves");

Tried with addOrCondition but still not working:

var qc = RelType.addQuery('name', 'Depends on::Dependent for');
qc.addOrCondition('name', 'Solved by::Solves');

 

RelType.query();
while (RelType.next()) {

alert("Cannot Resolve this Incident due to one or more Dependencies that have not been completed.");

}

 

Kindly help me with this issue. Thanks.

1 ACCEPTED SOLUTION

Did an example list filter:

find_real_file.png

Went to background script and wrote this:

var gr = new GlideRecord('task_rel_type');
gr.addEncodedQuery('name=Caused by::Causes^ORname=Contains::Task of');
gr.query();
if (gr.next()) {
gs.info("Found results: " + gr.getRowCount());
}

Result is:

find_real_file.png

So when you're saying it's not working, please elaborate, because it does work. What is the expected result? If you're referring to something else happening AFTER this...then ok...tell us what that is...but for the sake of the query, which is what you've made this thread about, it does work...

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

11 REPLIES 11

Michaela3
Kilo Contributor

Hi Imran,

maybe you have to use a second variable for the OR condition?

See following example:

var inc = new GlideRecord('incident'); 
var qc = inc.addQuery('priority','1'); 
qc.addOrCondition('priority','2');
inc.query(); 
while(inc.next()) { 
  // processing for the incident goes here 
}

Link: docs

Hi Michaela.. Thanks for your reply..

Well i tried that as well..

Tried with addOrCondition but still not working:

var qc = RelType.addQuery('name', 'Depends on::Dependent for');
qc.addOrCondition('name', 'Solved by::Solves');

 

RelType.query();
while (RelType.next()) {

alert("Cannot Resolve this Incident due to one or more Dependencies that have not been completed.");

}

Mike Patel
Tera Sage

RelType.addEncodedQuery("name=Solved by::Solves^ORname=Depends on::Dependent for");

should work as long as you have Depends on::Dependent for and Solved by::Solves.

just go to task_rel_type.list and verify you have record with that name.

I don't see "Depends on::Dependent for" any record in OOTB.

Hi Mike.. Yes, the records are available with these names as i said. The below query works perfectly when it is given individually.

 

var RelType = new GlideRecord('task_rel_type');
RelType.addQuery('name', 'Depends on::Dependent for');

 

var RelType = new GlideRecord('task_rel_type');

RelType.addQuery('name', 'Solved by::Solves');