addOrCondition() not working with addQuery() function !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2015 10:34 PM
Hello,
I need to write a multiple AND query along with OR conditions for addQuery() function.
When I try to write the following piece of code :-
var gr = new GlideRecord('sys_update_xml');
gr.addQuery('sys_updated_by',a).addOrCondition('sys_updated_by',c).addOrCondition('sys_updated_by',d);
gr.addQuery('target_name',aa).addOrCondition('target_name',ab);
gr.query();
I am writing it as a CLIENT SCRIPT. I also tried it by running it in the WORKFLOW but nothing worked.
Kindly help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2015 07:16 PM
You should not be using GlideRecord to query the database on the client side.
You need to do this in a business rule and call it via GlideAjax.
Also, OR conditions are done like this
var gr =new GlideRecord('incident');
var qc = gr.addQuery('category', 'hardware');
qc.addOrCondition('category', 'software');
gr.addQuery('priority','1');
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2015 08:45 PM
Paul is right, you might have to do this via a Business Rule or Glide Ajax. Client scripts are limited with Glide Record queries. There are some things you can't do, due to performance reasons.
Client Side GlideRecord - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2015 11:07 PM
Hi,
Try Below, make sure addQuery should have object of gliderecord.. here gr
var gr = new GlideRecord('sys_update_xml');
var pr = gr.addQuery('sys_updated_by',a);
pr.addOrCondition('sys_updated_by',c);
pr.addOrCondition('sys_updated_by',d);
var qr = gr.addQuery('target_name',aa);
qr.addOrCondition('target_name',ab);
gr.query();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2015 11:25 PM
Then wrap it up into a GlideAjax Script Include and call it with your client script!
Script include:
var AjaxExample = Class.create();
AjaxExample.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUpdateSets: function(){
var gr = new GlideRecord('sys_update_xml');
var pr = gr.addQuery('sys_updated_by',a);
pr.addOrCondition('sys_updated_by',c);
pr.addOrCondition('sys_updated_by',d);
var qr = gr.addQuery('target_name',aa);
qr.addOrCondition('target_name',ab);
gr.query();
while (gr.next() ) {
//Do processing here
}
return gr.getRowCount();
}
}
Client script
var ga = new GlideAjax('AjaxExample');
ga.addParam('sysparm_name','getUpdateSets');
ga.getXML(HelloWorldParse);
function serverResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
Remember, you can always do it in a business rule if there is no requirement to do it client side!
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022