How to get value from reference field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 01:02 AM
Hi Team,
Iam learning scripting and i have one use case.
Get the manager reference to user table from HR profile and populate on other scoped table field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 01:28 AM
Hello @preethigovi,
In your code if statement is missing, try below code:
var hrProfileGR = new GlideRecord('sn_hr_core_profile');
hrProfileGR.addQuery('sys_id=04556f50471f1110e72d7116536d43f9'); //sys id of HR profile record
hrProfileGR.query();
if (hrProfileGR.next()) {
var managerValue = hrProfileGR.getValue('manager');
var userValue = hrProfileGR.getDisplayValue('user')
gs.info('PreeManager value: ' + managerValue);
gs.info('PreeManager2 value: ' + userValue);
}
Please mark my solution as Accepted and Helpful, if it works for you in any way!
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 01:48 AM
Hello @preethigovi
Please add the if statement in the code. Please refer the below updated code:
var hrProfileGR = new GlideRecord('sn_hr_core_profile');
hrProfileGR.addQuery('sys_id', '04556f50471f1110e72d7116536d43f9'); // Use the sys_id you are querying for
hrProfileGR.query();
if (hrProfileGR.next()) {
var managerValue = hrProfileGR.manager;
var userValue = hrProfileGR.user.getDisplayValue(); // Display value of the user reference
gs.info('Manager value: ' + managerValue);
gs.info('User value: ' + userValue);
}
Please Mark Correct ✔️ if this solves your query and also mark Helpful 👍 if you find my response worthy based on the impact.
Regards,
Shruti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 01:50 AM
Hi @Shruti D @anshul_goyal Oops My bad it was my blunt mistake Thank You
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 02:01 AM
Hello @preethigovi ,
As manager field is available in the related list section. So, you need to glide to user table based on the HR profile record. Here is the below script you can follow as it is working in my PDI.
var hrProfileGR = new GlideRecord('sn_hr_core_profile');
hrProfileGR.addQuery("sys_id","b0e01de0832c5a1461ae9f65eeaad361"); //sys id of HR profile record
hrProfileGR.query();
if(hrProfileGR.next()){
var userValue = hrProfileGR.getValue("user");
var userProfile = new GlideRecord('sys_user');
userProfile.addQuery("sys_id",userValue);
userProfile.query();
if(userProfile.next()){
var managerValue = userProfile.manager.name;
var userValue = hrProfileGR.getDisplayValue("user");
gs.info("PreeManager2value is: "+ managerValue)
gs.info('PreeManager2 value: ' + userValue);
}
Please mark my solution as accepted and give thumbs up, if it helps you.
Regards,
Abhishek Thakur