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 02:03 PM
That is true, but if you want to make this BR work, you do need either Portal users or non-Portal users to have a standard way of identifying them. If anything, assigning a role to thousands of users via Fix script isn't going to take long, just ensure you use setWorkflow(false) to make it faster. If you go via that approach, ensure your new users have a way to receive the role automatically, depending on whether they will be Portal or non-Portal users.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2022 02:24 PM
I'm not sure if it will work in your case, but you might want to try:
var rp = typeof RP == 'undefined' ? new GlideRenderProperties() : RP;
gs.debug(rp.isPortal());
If you so give it a try, I would appreciate if you let us know whether it worked or not 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2023 08:27 PM
@Luis50
The following script makes the magic.... I was having the same problem
// return true or false based on if the BR is executed from the Classic or Portal
var rp = gs.action.getGlideURI().toString().startsWith('api/now/sp')
gs.addInfoMessage('RP: '+ rp);
if(!rp){
//execute the BR on Classic
} else {
//do nothing. Not execution on the Portal side
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2023 11:10 AM
@epinettiThe original poster hints at gs.action.getGlideURI() not being usable in the context.