- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 04:19 AM
Hi.
Im trying to create a user criteria for knowledge base.
The idea is to checking if the sys_user record and the field 'emai'l contains "@userdomain.com" returns to true then the user with email that have "@userdomain.com" should be granted access to the knowledge base with the defined user criteria.
if a users email contains for example "@wrong.userdomain.com" then it should be not granted any access to the knowledge base.
I've tried to put together a script, but the outcome is that any knowledge base that have the user criteria added to can read list is then available for all users, even the unauthenticated ones...
Script :
var user = new GlideRecord('sys_user');
var email = user.email;
if(email.indexOf("@userdomain.com") != -1){
answer = true;
}
else{
answer = false;
}
Is my script completely off?
Solved! Go to Solution.
- Labels:
-
Instance Configuration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 04:30 AM
Hi,
as best practice always use user_id to get logged in user sys_id
updated script
var user = new GlideRecord('sys_user');
if(user.get(user_id)){
var email = user.email.toString();
if(email.indexOf("@userdomain.com") != -1){
answer = true;
}
else{
answer = false;
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 04:24 AM
Try below
var usrid=gs.getUserID();
var useris = new GlideRecord('sys_user');
useris.addQuery('sys_id',usrid);
useris.query();
if(useris.next())
{
var emailis = useris.email;
if(emailis.indexOf("@userdomain.com") > -1){
answer = true; //show
}
else{
answer = false; //hide
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 04:30 AM
Hi,
as best practice always use user_id to get logged in user sys_id
updated script
var user = new GlideRecord('sys_user');
if(user.get(user_id)){
var email = user.email.toString();
if(email.indexOf("@userdomain.com") != -1){
answer = true;
}
else{
answer = false;
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2022 04:43 AM
Thank you so much
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-25-2024 12:30 AM
Hello Ankur,
my script below for user criteria is not working. Can you help me?