Adding an OR query in a before query business rule

Thomas Wright1
Tera Contributor

Hi all,

 

I'm looking to add an OR condition using a before query business rule for a query that is running with an OOTB script include. I'd like to avoid editing the script include itself.

 

I've already identified how to narrow down exactly when the query is being fired with a condition on the before query business rule.
What I'd like to do is take the existing query, and add an OR condition to it, so that more records are returned than are filtered by the original query in the script include.
I'm finding that whatever I try it just adds an AND condition, to further filter down the records that are returned, rather than opening up the records to more than the original filter.

I've tried using addEncodedQuery starting with "^NQmy_filter=blah" which just removed the ^NQ and made it an AND query. I've also tried using addOrCondition but couldn't get the syntax to work.

 

Anyone managed to achieve this?

4 REPLIES 4

Jon23
Mega Sage

Hi @Thomas Wright1 ,

Without knowing the OOB script include or business rule you are referring it hard to give a definitive answer.  Can you provide the BR and script names?

Hi @Jon23, this is on the source_request page of the Hardware Asset Workspace.

myinstance.service-now.com/now/hardwareassetworkspace/source_request/sc_task_sysId

I'm trying to play around with the list of stockrooms returned.

I've got the condition of my business rule as:
!(GlideTransaction.get().getRequest().getHeader("Referer").toString().indexOf("/source_request/") === -1)

Which only runs when I'm on the source_request page.

 

When I log current.getEncodedQuery() that prints out:

location=a9bd448b472b011042fca852736d434c

 

What I'd like to end up with is adding an OR condition to the above, so that it ends up as something like location=a9bd448b472b011042fca852736d434c^NQlocation=myotherlocationID

 

FYI I'm mostly playing around for my own knowledge, so not looking for an alternative solution. Just whether it's possible to edit a gliderecord query with a before query business rule to include more records than the original query

 

Another simpler scenario would be just to go to the incident table with a query of active=true. Would it be possible to be able to add an OR query so that the query ends up as active=true OR active=false using a before query business rule.


Another simpler scenario would be just to go to the incident table with a query of active=true. Would it be possible to be able to add an OR query so that the query ends up as active=true OR active=false using a before query business rule.

I was able to use the following in a before query business rule with no issue:

current.addEncodedQuery('active=true^NQactive=false');

Check out Query Business Rules: A Definitive Guide 

Ah yes okay, so I tried just 

current.addEncodedQuery('^NQactive=false');

That worked fine on the incident table.

Ended up with an encoded query of:

active=true^NQactive=false^EQ^ORDERBYDESCnumber

Adding an encoded query of

'active=true^NQactive=false'

Ended up with a redundant active=true filter

active=true^active=true^NQactive=false^EQ^ORDERBYDESCnumber

 

There must be something more complex going on with the query I'm trying to edit.