Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to check Catalog Item from Business rule?

nannielf
Tera Expert

Hi all!

 

We have Business rule at sys_user table, that using "current.addActiveQuery()" if current user is not admin.

At one of our Catalog Items at Service portal we need to show all users, not only active.

 

Is there any solutions how to check where we are from BR? 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

It sounds like you have a query Business Rule.  You can set your advanced reference qualifier to

activeANYTHING

preceded with a ^ if you are appending to an existing value.

In your query Business Rule, change the script to this, incorporating the admin check if that is in the script

(function executeRule(current, previous /*null when async*/) {
	var query = current.getEncodedQuery()
	if (gs.getSession().isInteractive() && !query.includes('activeANYTHING')) {
		current.addActiveQuery();
	}
})(current, previous);

View solution in original post

5 REPLIES 5

Brad Bowman
Kilo Patron
Kilo Patron

It sounds like you have a query Business Rule.  You can set your advanced reference qualifier to

activeANYTHING

preceded with a ^ if you are appending to an existing value.

In your query Business Rule, change the script to this, incorporating the admin check if that is in the script

(function executeRule(current, previous /*null when async*/) {
	var query = current.getEncodedQuery()
	if (gs.getSession().isInteractive() && !query.includes('activeANYTHING')) {
		current.addActiveQuery();
	}
})(current, previous);

delited

Hi! Thanks for your answer, but it's not actually that i'm looking for.

I need to ignore addActiveQuery() if we are on the specific item

I was trying this code but it doesn't work

 

	var query = current.getEncodedQuery();
	if (!query.includes('myItemID')) {
current.addActiveQuery();

 

 

The solution I provided will also work for specific Catalog Item(s) as you are only setting the reference qualifier on a variable in the specific item(s) - this can be just one item for now, then you don't need to change the script when the next case comes along. You need to change the reference qualifier and Business Rule script to that shown in the solution.  You can use this with your existing Condition so that the script doesn't run if the current user has the admin or user_admin role.  Since this already includes .isInteractive, you can omit the first condition from the if statement in the script. 

 

(function executeRule(current, previous /*null when async*/) {
	var query = current.getEncodedQuery()
	if (!query.includes('activeANYTHING')) {
		current.addActiveQuery();
	}
})(current, previous);