How to check if the record for a particular user is present or not in the user table. (not active or inactive)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2021 07:56 AM
Hi all,
I need a script include to check whether a particular user record is present in the user table or not.
I don't want to check whether the user is active or not...I want to check whether a particular record is present or not in the user table.
For example, In the above image the team lead escalation is "Mario", since the Mario is inactive, the record will not be present in the User table...so I cannot check with the condition active is true or false because the user record is not present in the table..
So, can anyone help me in writing a script to check whether a particular record is present or not in the user table.
Thanks,
Siva Jyothi.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2021 08:04 AM
Hi,
If the user is showing for selection within that field...then the record does exist in the user table.
Now, if you're saying if someone else like non-admin...goes to look and he doesn't show then he could still exist, but a before query business rule on the sys_user table is blocking inactive users from showing in this field...but again, the record still exists.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2021 08:08 AM
Hi,
Even if the user is inactive, it will be present in the user table.
Is that list collector referrring to which table? is it not user?
Here is the sample SI which you can use.
var chkUser = Class.create();
chkUser.prototype = Object.extendsObject(AbstractAjaxProcessor, {
initialize: function() {},
checkUser: function() {
var user = this.getParameter("sysparm_user").toString();
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", user);
gr.query();
if(gr.next()) {
return 'true';
}
return 'false';
},
type: 'chkUser'
});
Mark the comment as a correct answer and also helpful once worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2021 08:08 AM
Hi Siva,
Requirement : Create a function which will take input as userid or user sysid and will check in the user table if the user is active or not.
Script :
function isUserActive : function (userIdORUserSysID) {
var grUser = new GlideRecord('sys_user');
var query = gs.getMessage('sys_idSTARTSWITH{0}^ORuser_nameSTARTSWITH{0}',userIdORUserSysID);
grUser.addEncodedQuery(query);
grUser.query();
if(grUser.next()) {
return grUser.getValue('active')
}
}
Please mark correct/helpful.
Regards,
Amit Gujarathi
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi