How to write Query business rule for Or Condition? (^NQ) not working.

ashwanikumar
Tera Expert

Hi All,

I have a requirement to write Query Business rules for ITIL users based on support teams. I need to display records based on following condition. 

  • Filter A is the list of records based on their support group.
  • Filter B is in a case if incidents are raised for the user (requested for / requested by).

Both are connected with OR condition(refer to screenshot).

company=ca60733fdbc75340b828f5461d9619f2^service_offering.cost_center=3cf0306fdbcf9700a9e4f3d61d9619fc^assignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744^NQcaller_id=javascript:gs.getUserID()^ORu_on_behalf_of=javascript:gs.getUserID()^ORu_business_user=javascript:gs.getUserID()

company=ca60733fdbc75340b828f5461d9619f2^service_offering.cost_center=3cf0306fdbcf9700a9e4f3d61d9619fc^assignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744^NQcaller_id=javascript:gs.getUserID()^ORu_on_behalf_of=javascript:gs.getUserID()^ORu_business_user=javascript:gs.getUserID()

find_real_file.png

Issue is whenever I put ^NQ within addEncodedQuery in Query Business rule, it stops working. Is there any alternate solution for this?

Thanks,

KUMAR

1 ACCEPTED SOLUTION

Julian Hoch
ServiceNow Employee
ServiceNow Employee

^NQ is not supported in BR query rules. Since your B query only consists of OR queries, you can simply include that into your A query with additional OR conditions.

^NQ is only ever necessary if you have multiple queries each of which consist of multiple AND subconditions that have to be OR'ed together, which is not the case here.

View solution in original post

13 REPLIES 13

asifnoor
Kilo Patron

Hi,

Why don't you use addEncodedQuery instead of addQuery.

Copy the query from the filter and simply use gr.addEncodedQuery() and it should work.

Mark the comment as a correct answer and also helpful once worked.

I tried it. ^NQ doesn't work. that is the issue.

when you say it does not work, are you getting any error?

I just executed this code(few filters with AND and OR) and it is working fine in background script.

var gr=new GlideRecord("incident");
gr.addEncodedQuery("active=true^assigned_to=62826bf03710200044e0bfc8bcbe5df1^NQstate=1^assignment_group=b85d44954a3623120004689b2d5dd60a");
gr.query();
while(gr.next()) {
gs.print(gr.number);
}

I got the same results in the background as i see in the list view.

Mark the comment as a correct answer and helpful if it helps.

Julian Hoch
ServiceNow Employee
ServiceNow Employee

^NQ is not supported in BR query rules. Since your B query only consists of OR queries, you can simply include that into your A query with additional OR conditions.

^NQ is only ever necessary if you have multiple queries each of which consist of multiple AND subconditions that have to be OR'ed together, which is not the case here.

ashwanikumar
Tera Expert

An example of impact of ^NQ in List View:

I have grouped by Assignment Group. Now Under GHR Tier3 it is displaying different groups records.

Same behavior is under other groups. Count is (1) but if I expand it, it will show many records.

find_real_file.png