Run User Criteria on the basis of Session URL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2023 11:45 AM
Hi Community,
I am having a scenario in which I want to run User Criteria for a record producer only for Agent Workspace.
In short I want to restrict the user criteria for Portal. For that the below user criteria script is written but this is not working.
var url = gs.getProperty("glide.servlet.uri") + gs.action.getGlideURI();
var userRec = new GlideRecord("sys_user");
userRec.addEncodedQuery('location.country=INDIA^active=true');
userRec.query();
if (url.indexOf('workspace') > -1) {
if (userRec.hasNext())
answer = true;
else
answer = false;
}
Your reply will be helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2023 03:19 PM
hi @Harsh Ahuja ,
The script you provided checks if the URL contains the string "workspace", and if so, it checks if there is at least one active user in India, and sets the answer variable to true if there is, and false if there isn't.
To run this user criteria script only for the Agent Workspace, you need to modify the script to check if the current UI type is "navigator" or "navigator_mobile" before checking the URL. Here's an updated script that should work:
var userType = gs.getUser().getPreference('glide.ui.type');
if (userType == 'navigator' || userType == 'navigator_mobile') {
var url = gs.getProperty("glide.servlet.uri") + gs.action.getGlideURI();
var userRec = new GlideRecord("sys_user");
userRec.addEncodedQuery('location.country=INDIA^active=true');
userRec.query();
if (userRec.hasNext())
answer = true;
else
answer = false;
} else {
// User is not in Agent Workspace, so always return true
answer = true;
}
Thanks,
Rahul Kumar
Thanks,
Rahul Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2023 11:18 PM
I tried your script but sorry to say but it is not working, User criteria is not passing the conditions.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 12:02 AM
Hi Harsh,
You can try below code
var url = gs.getProperty("glide.servlet.uri") + gs.action.getGlideURI();
var isAgentWorkspace = url.indexOf('workspace') > -1;
if (isAgentWorkspace) {
var userRec = new GlideRecord("sys_user");
userRec.addEncodedQuery('location.country=INDIA^active=true');
userRec.query();
answer = userRec.hasNext();
} else {
answer = true; // allow access for Portal
}
Thanks,
Rahul Kumar
Thanks,
Rahul Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2023 11:32 PM
Thanks for your script, but even after writing this in user criteria script, the record producer is visible in both Portal & Agent Workspace & we want to make that visible only on agent workspace.