How to stop query rule from running when user is in the portal?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2022 07:55 AM
Hi,
I created a query business rule for the task table, however I wanted this rule to stop execution when the user calls it from a Service Portal (mainly because SP widgets have other ways of performing the query that differs a lot from the business rule in question) so I use the getGlideURI() function to accomplish this (see the example below).
var userInPortal = gs.action.getGlideURI().getMap().get('portal_id') != null ? true : false;
With that being said I keep seeing errors in the system logs coming from this rule, specifically a NullPointerException, I performed different tests with the script debugger and it seems to work as expected, so I came across this article I believe that basically answers why I'm seeing the errors but I'm yet to confirm which Job or Export action is causing it.
Is there another way to check if the user is in the Service Portal?
Or
Is there a way to stop the rule when called from a Job or Export?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2022 12:52 PM
That's a peculiar requirement. Mind if I ask you why do you want the Service Portal to have different query BR behaviour than that of platform? What's the story behind this? Maybe there is a better way to achieve what you need.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2022 01:29 PM
Sure thing, our IT organization inside ServiceNow is divided into Lines Of Business, so for anyone who accesses the Now Platform we force views and query rules based on the IT LOB that the users are part of, so they only see what they're supposed to see.
The Service Portal is mainly accessed by internal employees, with limited roles such as snc_internal and other custom ones we have created but they are not part of any LOB because they are not part of IT, these are users with Operational roles and titles and therefore the rules above restrict their ability of viewing even their own cases, incidents or requests.
However widgets such as My Requests, make use of request_filter, where you can specify the task types and conditions to limit or allow the visibility of the users interactions. That's why we stop the rule when the user is in the Portal.
I think I found a workaround and is the use of gs.isInteractive(), which works for Jobs but I'm not sure if it works for exports I'm still pending to confirm that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2022 01:37 PM
If you only want specific users to be affected by the query BR, why not add an advanced condition that checks something relevant for those users, e.g. a specific role?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2022 01:51 PM
That is a bit complicated because we're talking about thousands of users that don't necessarily have the same roles or something unique to them, I guess that's more of an issue with how things were designed to work initially, but that's what we have for now.