- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2017 12:27 AM
Hi All,
I would like to get the Manager id of in-active user id. So, to get the "In-active" user using Glide Record, I am using following script
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', gs.getUserID());
gr.query();
it return a user data along with his Manager id. But this manager record is as In-Active. So, I would like to get the Manager of this in-active manager. I use below script
but, it does not return any data
var gr1 = new GlideRecord('sys_user');
gr1.addQuery('sys_id', gr.manager);
gr1.query();
if (gr1.next())
{
gs.addInfoMessage('InActive Mgr:' + gr.name + ':' + gr1.manager);
}
it does not return any Inactive users data.
Is it possible to get any In-active user data using GlideRecord?
Could you please let me know any valuable guidance or suggestions ?
thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2017 12:13 AM
Hi
There is a default business rule on the sys_user table called "user query"
It will prevent non admin users from accessing inactive user records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2017 02:39 AM
Hi Lars Tange
Thanks a lot. Yes, the "user query" prevent this. If I comment this "current.addActiveQuery();" in this "user query" it returns the result.
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2017 02:44 AM
Hi Varadharaj,
I think that is not a best practice as it sets permission to everyone to access in-active users. what i can suggest you is follow the steps mentioned by Lars Tange.
Regards,
Sadasiva
Please mark helpful/ correct based on the impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 01:23 PM
Lars - can you share what your script include looks like for this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2017 12:48 AM
Hi
This is my function in the script include
searchInactiveUser: function () {
var answer = '';
var search = this.getParameter('sysparm_search');
gs.getSession( ).putClientData('searchInactive', 'true'); //Put session value to disable BR 'user query' temporarily
var user = new GlideRecord('sys_user');
user.addQuery('active',false);
user.addQuery('user_name','STARTSWITH',search);
user.query();
if (user.next()) {
answer = user.sys_id + "," + user.getDisplayValue();
}
gs.getSession( ).putClientData('searchInactive', 'false'); //Enable BR 'user query' again
return answer;
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2017 02:42 AM
Be careful of disabling this function, as it affects all other places in ServiceNow where you select a user record for something. Here users might by mistake select inactive users who does not work at your company any more.