- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2024 08:55 PM
I have to create a HR Form with a variable referencing HR Profile. After selecting the HR Profile, I want to get the employee number and department of the HR Profile from the associated User Profile.
I have tried catalog client scirpt and script include but it is not working for me. It will be great if you could help me out in the code.
Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var subjectPerson3 = g_form.getValue('what_is_your_name');
if (subjectPerson3) {
var ga = new GlideAjax('AskHR_UtilitiesAJAX');
ga.addParam('sysparm_name', 'getUserProfile');
ga.addParam('sysparm_hrprofile', subjectPerson3);
ga.getXMLAnswer(getUserProfileEmployee_Number);
}
}
function getUserProfileEmployee_Number(answer) {
if (answer) {
var returneddata = JSON.parse(answer);
g_form.setValue('employee_number', returneddata.employee_number);
}
}
Script Include:
getUserProfile: function() {
var hrProfile = this.getParameter('sysparm_hrprofile');
var hrProfileGr = new GlideRecord('sn_hr_core_profile');
hrProfileGr.addQuery('sys_id', hrProfile);
hrProfileGr.query();
if (hrProfileGr.next()) {
var userSysId = hrProfileGr.getValue('user');
var userGr = new GlideRecord('sys_user');
userGr.addQuery('sys_id', userSysId);
userGr.query();
if (userGr.next()) {
var employeeNumber = userGr.getValue('employee_number');
var results = {
'employee_number': employeeNumber
};
return new JSON().encode(results);
}
}
return '';
}
Variables:
what_is_your_name - Reference to HR Profile
employee_number - Single Text Field
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2024 05:48 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2024 10:05 PM
Hi there,
"I have tried catalog client scirpt and script include but it is not working for me"
What exactly is not working? Please provide us with info, preventing us from spending hours on your question.
You could also help yourself by adding debugging. Debugging will help you spot until where the scripting is working, from where its failing, if the values are what you expect, etc.. Instead of hours on something like, you would only be spending minutes.
So add debugging. If then still help needed, follow-up on this topic. Do provide us with the info!
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2024 04:39 AM
What exactly is not working? - Employee Number is not getting populated from the HR Profile input.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2024 05:04 AM
Okay, good luck in your search!
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2024 05:48 PM
I was able to split the catalog client script and got it working.