- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2023 08:13 PM - edited 09-12-2023 08:36 PM
I created a new tab in Form Section named User Details. Fields - User ID, Email, and Department was auto-populated after choosing Name of User. How do I get the Department value? I need to change the Assignment Group to 'IT Securities' when the Department is 'IT'.
Code below is not working.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2023 08:48 PM
I'm guessing the Department field on your form is dot walked from the "Name of User" field. You can try to dot walk the "Name of user" field.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var dept = g_form.getReference('Name of user FIELD NAME').department;
alert(dept);
if (dept === 'IT') {
g_form.setValue('assignment_group', 'IT Securities');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2023 08:48 PM
I'm guessing the Department field on your form is dot walked from the "Name of User" field. You can try to dot walk the "Name of user" field.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var dept = g_form.getReference('Name of user FIELD NAME').department;
alert(dept);
if (dept === 'IT') {
g_form.setValue('assignment_group', 'IT Securities');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2023 09:05 PM
Hi @jonsan09 ,
This getReference now works but I think it throws the sys_id of department. How do I convert this(9a7ed3f03710200044e0bfc8bcbe5db7) to actual word - 'IT'?
Apologies as I'm new in ServiceNow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2023 09:19 PM
You'll want to check your user table figure out table that department field is referencing and figure out the display field/name field for deparment. From there I believe you can keep dotwalking for example, I'm using name as an example but it might be different in your instance.
var DeptName = g_form.getReference('Name of user FIELD NAME').department.name;