- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2022 12:53 AM
Hi All,
I have to fetch the department ID of a user in my catalog, now I have a script include which fetches other user details like phone number, email, etc and populates it on the form. I want to get the department ID of that user which is actually contained in department table. Kindly help me fetch the same.
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2022 02:58 AM
Hi,
That is odd because the dot walk should work.
Could you try this version of the script?
var userDetailsUtil = Class.create();
userDetailsUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getEmployeeDetails: function () {
var userName = this.getParameter('sysparm_user');
var user = new GlideRecord('sys_user');
var result = {
//Create an object to store the User data
phoneNumber: '',
email: '',
location: '',
manager: '',
department: '',
};
if (user.get(userName)) {
var departmentRec = new GlideRecord('cmn_department');
departmentRec.addQuery('name', user.department.getDisplayValue().toString());
departmentRec.query();
if (departmentRec.next()) {
result.department = departmentRec.id.toString();
}
result.email = user.email.toString();
result.phoneNumber = user.mobile_phone.toString();
result.location = user.location.getDisplayValue();
result.manager = user.manager.getDisplayValue();
}
return JSON.stringify(result);
},
type: 'userDetailsUtil',
});
Hope this helps

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2022 12:58 AM
Hi,
Share your script include and I will add the changes to it.
Hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2022 01:23 AM
Hi Dan,
PFB.
var userDetailsUtil = Class.create();
userDetailsUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getEmployeeDetails: function() {
var userName = this.getParameter('sysparm_user');
var user = new GlideRecord('sys_user');
var result = { //Create an object to store the User data
phoneNumber: "",
email: "",
location: "",
manager: "",
department: ""
};
if (user.get(userName)) {
result.email = user.email.toString();
result.phoneNumber = user.mobile_phone.toString();
result.location = user.location.getDisplayValue();
result.manager = user.manager.getDisplayValue();
result.department = user.department.id.getDisplayValue();
}
return JSON.stringify(result);
},
type: 'userDetailsUtil'
});
If I just do user.department.getDisplayValue(), its giving me the Department name but to get the ID, the ID dotwalk is not working..

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2022 02:58 AM
Hi,
That is odd because the dot walk should work.
Could you try this version of the script?
var userDetailsUtil = Class.create();
userDetailsUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getEmployeeDetails: function () {
var userName = this.getParameter('sysparm_user');
var user = new GlideRecord('sys_user');
var result = {
//Create an object to store the User data
phoneNumber: '',
email: '',
location: '',
manager: '',
department: '',
};
if (user.get(userName)) {
var departmentRec = new GlideRecord('cmn_department');
departmentRec.addQuery('name', user.department.getDisplayValue().toString());
departmentRec.query();
if (departmentRec.next()) {
result.department = departmentRec.id.toString();
}
result.email = user.email.toString();
result.phoneNumber = user.mobile_phone.toString();
result.location = user.location.getDisplayValue();
result.manager = user.manager.getDisplayValue();
}
return JSON.stringify(result);
},
type: 'userDetailsUtil',
});
Hope this helps