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

johnfeist
Mega Sage
Mega Sage

Hi,

Department in the user table is a reference to cmn_department.  You can get the sys_id from the column in sys_user.  You can set up your column in a custom app as a string or a reference.  In most cases, the benefits of having it as a reference outweigh those of inserting a string and not having to do any relational look ups at run time.

You are able to insert the user directly because you can use g_user.userID.  In order to get the department, you need to create an AJAX call to retrieve the value from the server.  Here's the link to the documentation on AJAX.

On thing that many people miss is making sure that the server side script needs to be marked as client callable.

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

Prashant Ahire
Kilo Sage

Hi how did you complete this requirement