Can i use multiple addOrCondition in query?

Hulk1
Giga Contributor

var gr=new GlideRecord("table_name");

gr.addQuery("gender","male").addOrCondition("gender","female").addOrCondition("gender","transgender");

gr.query();

Can i use multiple addOr Condition in my query? If no any other way to do this?

2 REPLIES 2

Michael Jones -
Giga Sage

Typically speaking, yes, you can use multiple andOrConditions in the same query. For example, this one returns the 3 incidents that I expect in my PDI: 

gr.addQuery('short_description', 'No network access').addOrCondition('short_description', 'outlook not opening').addOrCondition('short_description', 'Email server is down.')

You can try breaking it down into smaller segments (just add one or condition) and see if you get results you expect.

You might also try building the query in a list view, making sure you see what you expect, and then copy the query from the filter and use addEncodedQuery and see what results you get. 

Multiple and / or conditions should work, but I've certainly encountered issues where I don't get the results that I expect and have to validate and adjust my query. 

I hope this helps!

If this was helpful or correct, please be kind and remember to click appropriately!

Michael Jones - Proud member of the CloudPires team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

Hai thanks for your reply. This is my code.

<<?xml version = "1.0"encoding = "utf-8" ? >
<j : jelly trim = "false" xmlns: j = "jelly:core" xmlns: g = "glide" xmlns: j2 = "null" xmlns: g2 = "null" >
<g: inline template = "reporting_includes.xml" / >
<g: inline template = "list2_js_includes.xml" / >
<g: evaluate var = "jvar_gr" object = "true" jelly = "true" >
var gr = new GlideRecord('table1');
var gr1 = new GlideRecord('table2');
var str = jelly.sysparm_active;
gr1.query();
while (gr1.next()) {
if (gr1.male == "true" &amp;&amp; gr1.female=="false" &amp;&amp; gr1.transgender=="false") {
gr.addQuery("gender", "male");
}
 

else if (gr1.male == "false" &amp;&amp; gr1.female=="true" &amp;&amp; gr1.transgender=="false") {

gr.addQuery("gender", "female");

}

else if (gr1.male == "false" &amp;&amp; gr1.female=="false" &amp;&amp; gr1.transgender=="true") {

gr.addQuery("gender", "transgender");

}

else if (gr1.male == "true" &amp;&amp; gr1.female=="true" &amp;&amp; gr1.transgender=="false") {

gr.addQuery("gender", "male").addOrCondition("gender","female");

}

else if (gr1.male == "true" &amp;&amp; gr1.female=="false" &amp;&amp; gr1.transgender=="true") {

gr.addQuery("gender", "male").addOrCondition("gender","transgender");

}

else if (gr1.male == "false" &amp;&amp; gr1.female=="true" &amp;&amp; gr1.transgender=="true") {

gr.addQuery("gender", "female").addOrCondition("gender","transgender");

}

}
gr.query();
gr;
</g:evaluate>
<html>
<head >

 

</head>

 

<body >
<div class = "col-md-10" >
<table border = "1" >
<tr >
<th > Name < /th>
<th > Id < /th>
<th > Gender < /th>
<th > UserId < /th>
</tr>
<g: for_each_record file = "${gr}" >
<tr >
<td > $ { gr.getValue("name") } < /td>
<td > $ { gr.getValue("id") } < /td>
<td > $ { gr.getValue("gender") } < /td>
<td > $ { gr.getValue("uid") } < /td>

 

</tr>
< /g: for_each_record >
</table>
< /div >
<div class = "col-md-2">
<input type = "checkbox" name = "male" id = "male" value = "${sysparm_male}" onclick = "filterchange('male')" / > Male
<input type = "checkbox" name = "female" id = "female" value = "${sysparm_female}" onclick = "filterchange('female')" / > Female
<input type = "checkbox" name = "transgender" id = "transgender" value = "${sysparm_transgender}" onclick = "filterchange('transgender')" / > Transgender
</div>
< /body >
</html>

 

</j:jelly>
 
Client Script:
 
function filterchange(val) {
var gr = new GlideRecord('table2');
if (val == "male") {
gr.query();
var checkedval1 = gel("male").checked;
if (checkedval1 == true) {
while (gr.next()) {
gr.male = "true";
gr.update();
}
} else {
while (gr.next()) {
gr.male = "false";
gr.update();
}
}
g_navigation.open("?sysparm_active="+val);
}

if (val == "female") {
gr.query();
var checkedval2 = gel("female").checked;
if (checkedval2 == true) {
while (gr.next()) {
gr.female = "true";
gr.update();
}
} else {
while (gr.next()) {
gr.female = "false";
gr.update();
}
}
g_navigation.open("?sysparm_active="+val);
}

if (val == "transgender") {
gr.query();
var checkedval3 = gel("transgender").checked;
if (checkedval3 == true) {
while (gr.next()) {
gr.transgender = "true";
gr.update();
}
} else {
while (gr.next()) {
gr.transgender = "false";
gr.update();
}
}
g_navigation.open("?sysparm_active="+val);
}
}
 
window.onload = function() {
initCheckBox();
};

function initCheckBox() {
var gr = new GlideRecord('table2');
gr.query();
while(gr.next())
{
if(gr.male=="true")
{
gel("male").checked=true;
}
if(gr.female=="true")
{
gel("female").checked=true;
}
if(gr.transgender=="true")
{
gel("transgender").checked=true;
}
}
}
 
Table1 data:
 
id.       name       uid.      gender
1.         aaa.         1          male
2          bbb          2          female
3          ccc          3           transgender
.
.
.
.
.
200     ggg         200         male
 
Table2 data:
 
male        female         transgender
false         false                false
 
 
It didn't work to me. What i need to change in this code. I have another one problem. When i click any checkbox it refreshes the whole page and fetched the report from table. To keep the checkbox checked after the page refreshed, i wrote initcheckbox() function in javascript. If i click male checkbox the value of a field male in table2 changed as true. If i closed the window and open again, now also the field value of male is true. so the male checkbox is remain checked. How to change the values of a table2 as false when the window is closed?