Bypass query business rule for catalog variable

shill
Mega Sage

I have an item in the catalog where I need the end users to be able to select disabled user records.

We currently have the typical before query business rule that limits those disabled records to HR and the Service Desk roles.

I still want to limit to only active users everywhere else. The only exception is this variable.

Is there a way I can avoid running this BR?

I was thinking a script include for an advanced ref qualifier, but I assume that still would trigger that BR.

1 ACCEPTED SOLUTION

ryanbalcom
Mega Expert

Hi Shill, 

I've recently encountered the same situation. I solved the problem by setting the reference qualifier on the variable to "activeANYTHING". Inside the "User Query" business rule I do something similar to:

var query = current.getEncodedQuery()

if( gs.getSession().isInteractive() && !query.includes('activeANYTHING') )

current.addActiveQuery()

 

Hope this helps you or others. Same idea can be used to bypass other query rules. 

Ryan

View solution in original post

14 REPLIES 14

That would work, but unfortunately this needs to be available to ALL users.


Giving roles to end users would increase our license count.


That would also force those in that role to have the ability to select disabled for all user reference fields, which I am trying to prevent, if anything, to avoid the clutter in the autocomplete or reference lists.


Dave Smith1
ServiceNow Employee
ServiceNow Employee

Steve Hill wrote:



That would work, but unfortunately this needs to be available to ALL users.


Okay, so... removing the admin check in the BR ought to do the trick.   Just worried it may have quite a wide blast radius.


Giving roles to end users would increase our license count.


Is this right?   I thought only specific roles were licenced - didn't think custom roles counted, since you'd then be charged for every new table created with roles created by default.


ryanbalcom
Mega Expert

Hi Shill, 

I've recently encountered the same situation. I solved the problem by setting the reference qualifier on the variable to "activeANYTHING". Inside the "User Query" business rule I do something similar to:

var query = current.getEncodedQuery()

if( gs.getSession().isInteractive() && !query.includes('activeANYTHING') )

current.addActiveQuery()

 

Hope this helps you or others. Same idea can be used to bypass other query rules. 

Ryan

Ryan,

I have a similar issue, and I really like your idea, as it just makes the exception for that particular catalog item/variable and nothing else.  However, I am already using the Reference Qualifier for an Advanced Filter:

manager=javascript:gs.getUserID()

Basically, the managers submitting this request should only see employees who report to them (whether active or not).

Is there a way to incorporate both things in my Reference Qualifier?

Thanks

OK, the light bulb went on and I figured it out.

Just changed this part:

... && !query.includes('activeANYTHING'))

to this:

... && !query.includes('manager=javascript:gs.getUserID()'))

and it worked!