Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Glide record HR profile table to fetch Employee number and Domain ID

Renu9
Tera Contributor

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. 

21 REPLIES 21

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 .

find_real_file.png

Hi Renu,

Great job...!!!

 

Please mark correct/helpful if its helpful to you...!!

 

Warm regards,

Vishal Birajdar

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

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 

Ankur Bawiskar
Tera Patron
Tera Patron

@Renu 

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

I tried with the BR you mentioned, but I dont see its working. Does this work on catalog form side.?