Glide record HR profile table to fetch Employee number and Domain ID
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2021 08:57 AM
I need to auto populate Employee number and domain id of the logged in user once the Service is opened from the portal.
I am writing an onLoad function in catalog client script and glide recording the sn_hr_core_profile table. number is the unique field in HR Profile table. But I am receiving an undefined message at the alert i used alert(g_user.number);. Can you please suggest me what i m missing here.
function onLoad() {
var reqgr = new GlideRecord('sn_hr_core_profile');
reqgr.addQuery('sys_id', g_user.number);
alert(g_user.number);
reqgr.query();
while(reqgr.next())
{
g_form.setValue('us_domain_id', reqgr.u_domain_id);
g_form.setValue('employee_number', reqgr.employee_id);
}
}
Let me know if anything needed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2021 02:54 AM
Hi Vishal,
For this, the sys id of the user in HR profile and sys_user is different right, so, getting 0 rows count.
I created another gliderecord with sys_user table and got the user name from it and stored in a variable and passed this variable to the HR profile glide record. It then worked. Please find below. Thanks much for your assistance .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2021 12:01 AM
Hi Renu,
Great job...!!!
Please mark correct/helpful if its helpful to you...!!
Warm regards,
Vishal Birajdar
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2023 06:14 AM
Hello Renu
I m also working on same requirement can share your code so I Can Understand How Can we Get Details from HR Profile Table
regards
Harshal Nirmal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2021 07:59 PM
why not use before insert BR to populate the details?
I assume the Domain ID and Employee ID is stored in HR Profile for every user
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('sn_hr_core_profile');
gr.addQuery('user', gs.getUserID());
gr.query();
if(gr.next()){
current.us_domain_id = gr.u_domain_id;
current.employee_number = gr.employee_id;
}
})(current, previous);
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
‎03-07-2021 11:17 PM
Hi Ankur,
I tried with the BR you mentioned, but I dont see its working. Does this work on catalog form side.?
