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

larstange
Mega Sage

Hi



If you are displaying all your code above you need to add



gr.next(); after gr.query() to get the record



Alternatively do:



var gr = new GlideRecord('sys_user');


gr.get(gs.getUserID());


Siddartha Gudim
Tera Guru

aScript is basically filtering gout the person logged in. In this case its "U". Its because of this line -->> gr.addQuery('sys_id', gs.getUserID());




If you want the managers of inactive users please use this code


var text='User Name: ';


var gr = new GlideRecord('sys_user');


gr.query('active',false);


gr.query();


while(gr.next())


{



text = gr.name+'   \n\ Manager Name:';



text+=gr.manager.getDisplayValue();


}


}




This will return the inactive users manager name



please specify your requirement briefly so that I can assist you more.



Please like or mark correct based on the impact of response.


Hi Siddartha,



Thanks a lot for your immediate response.



My requirement is, I have to populate the logged in user's manager name. If that logged in manager is In-actvie, then I have to show the manager of this "In-active" manager.



As per your suggestion, I have already used the filter like "gr.addQuery('active', false);


it does not bring any records.



Your suggestion will be more helpful.



thanks


Use this code if works




doThis(gs.getUserID());



function doThis(user){



var text='User Name: ';


var gr = new GlideRecord('sys_user');


gr.addQuery('sys_id',user );


gr.query();


while(gr.next())


{


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


{


gs.addInfoMessage('manger is ' +gr.manager.getDisplayValue());


}


else{


doThis(gr.manager);


}


}


}



Please like or mark correct based on the impact of response.