- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 05:23 AM
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.
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 06:53 AM
Did an example list filter:
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:
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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 05:30 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 05:34 AM
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.");
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 05:35 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 05:44 AM
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');