- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 04:50 AM
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!
Solved! Go to Solution.
- Labels:
-
User Experience and Design

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2020 05:28 AM
Taking the Incident form lay-out as example. You could add the field doltwalked like:
If I now select a User which has a Department, like on my PDI "HR" is my department, automatically the Department is shown:
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 05:03 AM
Hi, Based on logged in user you want to populate users department.
If yes then create onLoad client script as below,
function onLoad() {
var ga = new GlideAjax('ScriptIncludeDemo');
ga.addParam('sysparm_name','GetDetails');
ga.getXML(callback);
function callback(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('deparment',answer);
}
}
write script include
SI name - ScriptIncludeDemo
client callable - checked
var ScriptIncludeDemo = Class.create();
ScriptIncludeDemo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
GetDetails : function()
{
var user = gs.getUserID();
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',user);
gr.query();
while(gr.next())
{
return gr.department.name;
}
},
type: 'ScriptIncludeDemo'
});
Mark correct/helpful based on impact.
Thanks,
Dhananjay.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 05:09 AM
Be aware that Department is a reference field looking at the example. So only providing the sys_id or name, causes an additional call to be made (= performance loss).
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2020 05:00 AM
Yeah thats correct.
Thanks Mark.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 05:03 AM
Hi,
Can you try this in the default value of Department field .
javascript:gs.getUser().getDepartmentID();
Please mark this accepted/helpful, if applicable.
Thanks & Regards,
Sharjeel
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2020 04:52 AM
Sharjeel, this does not seem to populate the Department field with the value from the User [sys_user] table. However, I appreciate the recommendation.