- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2022 08:14 PM
Hello everyone. Im a newbie in servicenow and I'm kinda lost in getting the value of the field in sys_user table .
My requirement is to update every month the "HR Partner EID" of the users in a custom table.. I need to reference it in the sys_user table field named "HR People Advisor Name".
Example: If the HR people advisor name in the user table is "Maria Foj" , it should also display the same name in the HR partner EID field that is in the custom table.
Custom table field:
User Table field:
What I did was , I created a scheduled job that will run every month but I really didnt get the value from HR people advisor name to be displayed in the HR partner eid field.
All your responses will be a great help to me. Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2022 03:27 AM
If it's a reference then it can hold user sysId and not u_hrrepnm
In that case the script I shared will work fine
try{
var gr = new GlideRecord("custom table");
gr.addQuery("u_apprentice_statusINactive_loa,active");
gr.addEncodedQuery("u_apprentice_eidISNOTEMPTY");
gr.query();
while (gr.next()) {
var user = new GlideRecord('sys_user');
if(user.get('user_name', gr.u_apprentice_eid)){
gr.u_hr_partner_eid = user.getUniqueValue();
gr.update();
}
}
}
catch(ex){
gs.info(ex);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2022 09:45 PM
Hi,
can you share these details?
hrpeopleadvisor -> field on user table which needs to be fetched
u_apprentice_eid -> on table apprentice is holding reference to User table or holds user_name
u_hr_partner_eid -> field on apprentice table which will be populated
As per my assumptions here is the script; enhance it
try{
var gr = new GlideRecord("custom table");
gr.addQuery("u_apprentice_statusINactive_loa,active");
gr.addEncodedQuery("u_apprentice_eidISNOTEMPTY");
gr.query();
while (gr.next()) {
var user = new GlideRecord('sys_user');
if(user.get('user_name', gr.u_apprentice_eid)){
gr.u_hr_partner_eid = user.getUniqueValue();
gr.update();
}
}
}
catch(ex){
gs.info(ex);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2022 12:57 AM
Did you get a chance to check on the script I shared above?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2022 01:26 AM
Hi
Fields:
HR People Advisor -> u_hrrepnm
-field on user table which needs to be fetched
Apprentice EID -> u_apprentice_eid
-on table apprentice is holding reference to User table or holds user_name
HR Partner EID -> u_hr_partner_eid
-field on apprentice table which will be populated
I also tried to make changes and query a specific record in the custom table to see if its working in one record ,but still not working...
var gr = new GlideRecord('customtable');
gr.addEncodedQuery('u_apprentice_statusINactive_loa,active');
gr.addEncodedQuery('u_apprentice_eid=044fcb89db19b09031df7a43e29619f9Y');
gr.query();
while (gr.next()) {
var user = new GlideRecord('sys_user');
if(user.get('user_name', gr.u_apprentice_eid)){
gr.u_hr_partner_eid = user.getDisplayValue('u_hrrepnm');
gr.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2022 01:43 AM
Hi,
u_hr_partner_eid on custom table is reference right then how can it hold string field from user record?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2022 01:48 AM