Simple query returns null value

rjp
Tera Expert

Hi,

I have a script that calls a query to return the Employee name and Manager for that employee.  It correctly returns the name (highlighted in green below) but does not return the manager (highlighted in yellow below) 

usrCount4 = new GlideRecord("sys_user");
usrCount4.addQuery("user_name",usrCount3.u_person.name);
usrCount4.query();
while(usrCount4.next()){
gs.log('here5');
gs.log('Employee Name: '+usrCount4.getValue("name") ); <--- this line not work
gs.log('Student Name: '+usrCount4.getValue("manager") ); <--- this line does not work
}

this is the results that are returned...

find_real_file.png

please let me know if you see anything wrong with the script.

THanks,

Robert 

1 ACCEPTED SOLUTION

Chander Bhusha1
Tera Guru

Hi Rjp,

It return null as the manager is not present for the record which you are querying 

and if you need the displayvalue of manger name then you have to use the displayValue.

Use the script below:

var usrCount4 = new GlideRecord("sys_user");
usrCount4.addQuery("user_name",usrCount3.u_person.name);
usrCount4.query();
while(usrCount4.next()){
gs.log('here5');
gs.log('Employee Name: '+usrCount4.getValue("name") );
gs.log('Student Name: '+usrCount4.getDisplayValue("manager") ); <--- this line does not work
}

Check the record that if it has manager or not if the manger is not present for the record you are querying then it will shown null which is working fine.

 

Mark helpful and correct if it helps.

Thanks,

CB

View solution in original post

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

This is really confusing as the log doesn't match your description of what you say is working, then later you say both lines do not work.  I don't think that log section is from this code.  If it's employee name and manager, why say Student Name?  In any event "manager" is going to be a sys_id, so you either need to log usrCount4.manager.name, or usrCount4.getDisplayValue("manager").

Chander Bhusha1
Tera Guru

Hi Rjp,

It return null as the manager is not present for the record which you are querying 

and if you need the displayvalue of manger name then you have to use the displayValue.

Use the script below:

var usrCount4 = new GlideRecord("sys_user");
usrCount4.addQuery("user_name",usrCount3.u_person.name);
usrCount4.query();
while(usrCount4.next()){
gs.log('here5');
gs.log('Employee Name: '+usrCount4.getValue("name") );
gs.log('Student Name: '+usrCount4.getDisplayValue("manager") ); <--- this line does not work
}

Check the record that if it has manager or not if the manger is not present for the record you are querying then it will shown null which is working fine.

 

Mark helpful and correct if it helps.

Thanks,

CB

rjp
Tera Expert

Great thank you for your quick and accurate responses!