- 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 08:40 PM
Hi,
So you will have to iterate the custom table and check if the apprentice field is empty or not
Can you explain which field in custom table holds the user reference or user_name? based on that you can know
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:13 PM
Hi
I have to query the custom table to all records that are in "Active" state only because some of the records in the custom table are already in a "complete" state records.. In short, I only just need to update all the HR Partner EID(custom table field) in "Active" state records every month.
The field that holds the user_name in the custom table is the "u_apprentice_eid".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2022 09:34 PM
share the script here so that we can help
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:37 PM
Hi
Here's what Ive done so far
var user= new GlideRecord('sys_user');
var hrpeopleadvisor = user.getValue('u_hrrepnm');//the field where we need to get the value for HR Partner EID field.
var gr = new GlideRecord('apprentice');//custom table
var hr = gr.u_hr_partner_eid;//custom table field that needs to be updated every month
var id = gr.getValue('u_apprentice_eid');//user in the custom table
gr.addEncodedQuery('u_apprentice_statusINactive_loa,active');//records are active
gr.query();
if(gr.next()){
hr.setValue('hrpeopleadvisor');
}