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

Deepak Ramar1
Tera Expert

Hi Kumar,

Fix for incorrect reference links while using (^NQ) operator : https://community.servicenow.com/community?id=view_idea&sysparm_idea_id=26aaaafddb4011d45205e6be1396...

Solution : Whenever we use ^NQ operator to join multiple queries to build a master query

we need enter ^current.getEncodedQuery() at every (^NQ) operator JOINs before moving to final encoded query


Example :


Levelcheck1 : hr_service.u_service_entity=3ef7cbc287e68d900d9f7447cebb359d

Levelcheck2 : hr_service.u_service_entity=0e974b8287e68d900d9f7447cebb35e2^assignment_group=fe7be44b8751b0100d9f7447cebb3515

Levelcheck3 : number=HRC0052382^ORnumber=HRC0001703



Mergedquery1 = Levelcheck1+^NQLevelcheck2+ "^" + current.getEncodedQuery();
Mergedquery2 = Mergedquery1+^NQLevelcheck2+ "^" + current.getEncodedQuery();


current.addEncodedQuery(Mergedquery2)



Regards,
Deepak R

This was really helpful. 

Harish Murikina
Tera Guru

It is possible , the below script worked for me.

 

Harish Murikina
Tera Guru

It worked for me 

 

var groups = getMyGroups()+'';
var result = groups.substring(1, groups.length-1);

var qcOne = 'assignment_groupIN'+result+'^u_restricted_security_ticket=true^ORu_restricted_security_ticket=false^ORcaller_id='+u+'^ORopened_by='+u+'^ORwatch_listLIKE'+u;
var qcTwo = 'u_restricted_security_ticket=false';

var mergedQueryCondition = qcOne+'^NQ'+qcTwo+ "^" + current.getEncodedQuery();

current.addEncodedQuery(mergedQueryCondition);