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

Roffy
Tera Contributor

Just a heads up,

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

is going to include inactive users on any reference field or variable that contains this filter across your instance, which might be unwanted behaviour.

 

You can still utilise

!query.includes('activeANYTHING')

by adding "activeANYTHING^" to the start of your variable's reference qualifier so that it reads:

activeANYTHING^manager=javascript:gs.getUserID()

Quote:

Just a heads up,

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

is going to include inactive users on any reference field or variable that contains this filter across your instance, which might be unwanted behaviour.

Yes, I know, and that is the desired behavior.  Note I mentioned in my original question:

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

Actually, most of the time, they will be making submissions for terminated employees for this project (it is a request for access to folders of terminated employees and/or access to their email folders).

Thanks for this, worked perfectly. Any ideas on how to make a catalog client script then also return values for other variables off of this? The users can choose the inactive users now, but trying to populate other variables is returning undefined.

 

Thanks

-Chris

Roffy
Tera Contributor

Hi Chris,

 

I got around this by adding query condition:

sysUserGR.addQuery('activeANYTHING');

to my sys_user GlideRecord when fetching user values, which causes the "User query" business rule to be bypassed.

 

On a side note, I had to further adapt the business rule so that 'restricted' values display on the Service Portal ticket page. Our business rule now reads:

var query = current.getEncodedQuery();
var urlOnStack = gs.getUrlOnStack();

// Includes inactive users when "Active is anything" filter is set or when user is on a 'ticket' Service Portal page
if (!query.includes('activeANYTHING') && !urlOnStack.includes('id=ticket'))
	current.addActiveQuery();

Thanks! worked perfectly!