- 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-15-2024 08:04 PM
@Bhavya11 Its reference to user table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2024 08:12 PM
Hi @preethigovi ,
your script your fetching display value then setting that with the reference field so its not work.
var hrProfileGR = new GlideRecord('sn_hr_core_profile');
hrProfileGR.addQuery('number=HRP3083319^u_managerISEMPTY');
gs.info('PT1');
hrProfileGR.query();
if (hrProfileGR.next()) {
gs.info('PT Success');
var userGR = new GlideRecord('sys_user');
if (userGR.get(hrProfileGR.user)) {
var hiringManager = userGR.manager;
hrProfileGR.setValue('u_manager', hiringManager);
hrProfileGR.update(); // Save changes
gs.info('Hiring Manager set to: ' + hiringManager);
} else {
gs.info('User record not found.');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2024 07:59 PM
- 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-16-2024 08:38 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader