- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2024 11:55 PM
Hi Team,
I was learning on scripting where i had uses case to fetch manager (reference to user table) in HR profile and populate on filed on other scoped table
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2024 08:39 PM
use this script
var hrProfileGR = new GlideRecord('sn_hr_core_profile');
hrProfileGR.query();
while (hrProfileGR.next()) {
var userValue = hrProfileGR.getValue("user");
var userProfile = new GlideRecord('sys_user');
if (userProfile.get(userValue)) {
hrProfileGR.u_manager = userProfile.manager;
hrProfileGR.update();
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 01:57 AM
Hi @preethigovi ,
Hope all the field backend value is correct .please add hrProfileGR.next() it will work
var hrProfileGR = new GlideRecord('sn_hr_core_profile');
hrProfileGR.addQuery('sys_id=04556f50471f1110e72d7116536d43f9');
hrProfileGR.query();
if(hrProfileGR.next()){
var managerValue = hrProfileGR.getValue('manager');
var userValue = hrProfileGR.user.getDisplayValue();
gs.info('PreeManager value: ' + managerValue);// return sys_id if it is refernece field
gs.info('PreeManager2 value: ' + userValue);
}
Please mark this as Correct or Helpful if it helps.
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 02:02 AM
Yea @Bhavya11 Thank You its my mistake of not noticing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 02:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 02:07 AM
Hello @preethigovi ,
You can follow the below script;
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 userValue = hrProfileGR.getDisplayValue("user");
var managerValue = userProfile.manager.name;
gs.info("PreeManager Value is: "+ userProfile.manager.name);
gs.info('PreeManager value: ' + managerValue);
gs.info('PreeManager2 value: ' + userValue);
}
Please mark my solution as accepted and give thumbs up, if it helps you.
Regards,
Abhishek Thakur
it will return the manager and the username.