Get Inactive users using GlideRecord

varadharaj_a
Kilo Contributor

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

1 ACCEPTED SOLUTION

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


View solution in original post

31 REPLIES 31

Hi Sadasiva,



Really, thanks a lot your great effort and help.


Your script is good. It is working fine as per the script.



But my requirement is, as per your data, I need the Manager name of "Abel Tuter".




thanks


If your requirement is fulfilled .. please mark correct so that others can find the solution easily..



Regards,


Sadasiva



Please mark helpful/ correct based on the impact


If your requirement is fulfilled .. please mark correct so that others can find the solution easily..



Regards,


Sadasiva



Please mark helpful/ correct based on the impact


Hi Sadasiva,



Good Morning...



As per your given data, your script is correct.


However, my requirement is as below


I am login as user "AAA"


"BBB" was the manager of "AAA". But "BBB" is no longer in the organisation. So, his user record is as "In active"


However. "CCC" is the manager of "BBB". Now, If I login as "AAA" it should show the manager "CCC" instead of "BBB".



Hope, now the requirement is made clear.



thanks


Then you have to continue the loop till the manager is found...



doThis(gs.getUserID());



function doThis(user){



var gr = new GlideRecord('sys_user');


gr.addQuery('sys_id',user );


gr.query();


if(gr.next())


{


if(gr.manager != ''){



        if(gr.manager.active!='false')


        {


        gs.print('manager is active' +gr.manager.name);


        }


        else{


        doThis(gr.manager);


        }


        }


else{


gs.print('manager field is blank in User '+gr.manager.name+' record');


}


}


}



Regards,


Sadasiva



Please mark helpful/ correct based on the impact