- 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 06:01 AM
Since I see
alert("Cannot Resolve this Incident due to one or more Dependencies that have not been completed.");
I feel like you are doing this in Client Script and doing GlideRecord query in client script not recommended. Use GlideAjax to return the value.
SI:
var commonUtil = Class.create();
commonUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRelType: function(){
var gr = new GlideRecord('task_rel_type');
gr.addEncodedQuery("name=Solved by::Solves^ORname=Depends on::Dependent for");
gr.query();
if(gr.next()){
var msg = 'Cannot Resolve this Incident due to one or more Dependencies that have not been completed.';
return msg;
}else{
return '';
}
},
type: 'commonUtil'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('commonUtil');
ga.addParam('sysparm_name', 'getRelType');
ga.getXMLAnswer(function(answer){
if(answer != ''){
alert(answer);
}
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 06:45 AM
Hi Mike.. The code is within the script include.. I just mentioned a part of line which isn't working.
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.addEncodedQuery("name=Depends on::Dependent for^ORname=Solved by::Solves");
//var qc = RelType.addQuery('name','Depends on::Dependent for');
//qc.addOrCondition('name', 'Solved by::Solves');
RelType.query();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 05:44 AM
Hi,
For your addEncodedQuery, that should be pretty simple to figure out. You can just go to the list view, for example, for those records and filter it all how you want...for example:
I want all Incidents that are active and currently assigned to Service Desk, so I went to my Incidents list view and filtered appropriately...then I'm going to right-click the last piece of the breadcrumb and copy the query:
Now my encoded query is simply: active=true^assignment_group=d625dccec0a8016700a222a0f7900d06
So in your query script you'd use:
RelType.addEncodedQuery('active=true^assignment_group=d625dccec0a8016700a222a0f7900d06');
Please mark reply as Helpful/Correct. 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 06:43 AM
Hi Allen.. Yes that's the same thing i did. Below is the code. But still it is not working.
var RelType = new GlideRecord('task_rel_type');
RelType.addEncodedQuery("name=Depends on::Dependent for^ORname=Solved by::Solves");
But when i give individually like below, it works perfectly.
var RelType = new GlideRecord('task_rel_type');
RelType.addQuery('name', 'Depends on::Dependent for');
or
RelType.addQuery('name', 'Solved by::Solves');

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