- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2020 12:28 PM
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...
please let me know if you see anything wrong with the script.
THanks,
Robert
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2020 12:35 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2020 12:35 PM
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").
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2020 12:35 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2020 12:54 PM
Great thank you for your quick and accurate responses!