We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

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,

your BR is on which table?

Also is this for record producer or service catalog?

Regards
Ankur

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

It's a record producer, should auto populate fields such as employee number , domain id from the HR Profile table. BR is on sn_hr_core_case table

Hi,

then does your logged in user have HR profile in HR Profile table?

If yes then does that record have those 2 fields populated?

Regards
Ankur

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

Hi, Yes . The logged in user have HR profile record in the HR profile table. Yes , that record have 2 fields domain id and employee number

Hi,

is this happening for admins or non-admins

what came in BR logs?

Are you using correct field name for us_domain_id?

(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()){

gs.info('Record found domain ID' + gr.u_domain_id);
gs.info('Record found Employee number' + gr.employee_id);

current.us_domain_id = gr.u_domain_id;
current.employee_number = gr.employee_id;

}

})(current, previous);

Regards
Ankur

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