How to auto populate Department from the User [sys_user} table

carlavanskaik
Giga Contributor

This is the first custom application attempted. 

I would like to auto populate the value from the User [sys_user] department field, but I'm not quite sure how to do that. (Refer to attached screen print)  I was able to successfully auto populate the Requestor field, but am having trouble with the Department field.

Perhaps the missing link for me is that I must somehow associate the Department field value with the Requestor's User ID. Unfortunately, I'm not sure how to do that.

So, I appreciate any help which can be provided!

1 ACCEPTED SOLUTION

Taking the Incident form lay-out as example. You could add the field doltwalked like:

find_real_file.png

find_real_file.png

If I now select a User which has a Department, like on my PDI "HR" is my department, automatically the Department is shown:

find_real_file.png 

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

16 REPLIES 16

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Should this happen onChange? Or after saving the form?

An option might be to display the dotwalked department from the sys_user, on your form. 

An other option, if onChange, have a look at applying GlideAjax within a Client Script in combination with a Script Include. You could also use other techniques like getReference, though GlideAjax (with getXMLAnswer) performs by far best.

See below article which contains detailed explanation and examples:
Client Side Scripting: Go for GlideAjax (with getXMLAnswer)!

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Mark, I envisioned this happening when the form is loaded based on the department of the Requestor.  Also, I do not expect the Requestor to change since it is the person who is logged in.

I'm not quite sure how to display the dotwalked department from the sys_user, on your form

Taking the Incident form lay-out as example. You could add the field doltwalked like:

find_real_file.png

find_real_file.png

If I now select a User which has a Department, like on my PDI "HR" is my department, automatically the Department is shown:

find_real_file.png 

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Mark, I was able to easily utilize the dotwalking functionality to populate the Department field based on your guidance.  Thank you!