How to get the ID of a department from a user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2022 04:48 PM - edited ‎12-07-2022 04:55 PM
Hi,
I want to get the ID of a department from a user.
I'm doing a dot walk with getReference, but I can't get it.
*Catalog client scripts
How do I get it?
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2022 05:37 PM
Hi, as a client-side requirement, I would look at GlideAjax to lookup\return the information you require
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2022 05:40 PM
Hi @mi2022 ,
You'll not get department name by getting reference from sys_user table. You'll only get the sys_id of department as that's what is actually stored at user level. Dot walking works in business rules but not at client script level. So either you'll have to do two getReference (one for user and second for department) or you can write a GlideAjax as you've mentioned in your post.
I hope this helps
Please mark my answer correct if this helps you
Thanks
Mohit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2022 06:57 PM - edited ‎12-07-2022 07:04 PM
@mi2022 There is department field on users table
Script in catalog client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.getReference('<USER REFERENCING FIELD HERE>', getDepartment); // getDepartment is our callback function
}
function getDepartment(user) { // reference is passed into callback as first arguments
alert('Users department is :'+user.getValue('department'));
}
Assuming you are using on change client script.
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023