- 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-11-2020 02:29 AM
We have a script include which is called in the UI Action " Resolve Incident ", where we check if the incident is child of any other incident or if the incident has any dependent task to be completed or to check if any change solves this particular incident. If any of these conditions are met then throw an alert that there is an dependency.
Where as we are able to check the dependency individually by querying it , but when we query it with OR condition it is not working as expected. Kindly let me know where is it going wrong? Any other way to implement it.
When i try each one of these independently it works fine..
RelType.addQuery('name', 'Depends on::Dependent for');
//RelType.addQuery('name', 'Solved by::Solves');
//RelType.addQuery('name', 'Parent Of::Child Of');
But when i combine these with OR condition it doesn't work:
RelType.addQuery('name', 'Depends on::Dependent for').addOrCondition('name', 'Solved by::Solves');
Script include:
var corOpenDependencies = Class.create();
corOpenDependencies.prototype = Object.extendsObject(AbstractAjaxProcessor, {
OpenDependencies: function() {
var sysID = this.getParameter('sysparm_sysid');
var flag = 'false';
var ParentSysID;
var ParentSysID1;
var answer1 = "false";
//gs.log(answer, 'answer');
var answer2;
/////////////////////////////////////////////////////////
// Get the object for the 'Depend on' Relationship type.
/////////////////////////////////////////////////////////
var RelType = new GlideRecord('task_rel_type');
RelType.addQuery('name', 'Depends on::Dependent for');
//RelType.addQuery('name', 'Solved by::Solves');
//RelType.addQuery('name', 'Parent Of::Child Of');
//RelType.addQuery('name', 'Depends on::Dependent for').addOrCondition('name', 'Solved by::Solves');
RelType.query();
///////////////////////////////////////////////////
// Only proceed if the relationship types exists.
// Check for both the relationships.
///////////////////////////////////////////////////
while (RelType.next()) {
////////////////////////////////////////////////////
// Set the default value of the parent relationship
// to look for. We start with the SYSID passed in.
////////////////////////////////////////////////////
ParentSysID = sysID;
}
////////////////////////////////////////////////////////////////
// Search for all related records that this record
// is related to as a child and using the 'Depends On'
// relationship.
////////////////////////////////////////////////////////////////
var Rel = new GlideRecord('task_rel_task');
Rel.addQuery('parent', ParentSysID);
Rel.addQuery('type', RelType.sys_id);
Rel.addQuery('child.active', true);
Rel.query();
var req;
while (Rel.next()) {
flag= "true";
req=Rel.child;
//gs.log(req,'n');
var ReqTask = new GlideRecord('sc_task');
ReqTask.get('request_item.request', Rel.child);
if(ReqTask.state!='6' && ReqTask.state!='3'){
answer1 = "true";
}
}
if(flag == "true" && answer1 == "true")
{
answer2 = "true";
}
else
{
answer2 = "false";
}
//gs.log(answer2,'ammy');
return answer2;
},
type: 'corOpenDependencies'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2020 05:20 AM
Hi,
As I mentioned above, please try using EncodedQuery. You can get the query by simply going to your list view of these records, building your filter, then right-click the last piece of the breadcrumb and choose "copy query". From there, you can then use:
RelType.addEncodedQuery('paste_query_here');
Please mark reply as Helpful. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!