- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-04-2023 07:43 AM
Hello everyone,
I am currently trying to auto-populate a field on my Cat Item.
It should have the Head of Department of the Users department (cmn_department)
What type of variable should I use and what if I in the future the customers want to have multiple "Head of Department" - User? How can I make this work with one and what would change if the future case happens?
I have attached my current response but couldn't decide how to actually auto-populate it.
Thanks to everyone in advance š
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-07-2023 01:54 AM
Ok so I found the solution to it.
By adding the following lines to the "Default Value" it auto-fills it with the right dept_head:
javascript:var userDept=gs.getUser().getDepartmentID();
var deptHead='';
var deptGR=new GlideRecord('cmn_department');
if(deptGR.get(userDept)){deptHead=deptGR.getValue('dept_head');}
deptHead;
Thanks again everyone nonetheless š
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-04-2023 08:47 AM
Hello @Konstantinos Di
Greetings!
try the below script in Default Value.
javascript: gs.getUser().getDepartmentID()
(This only works in non scoped app).
Please Mark the Answer as correct solution and helpful if helped!
Kind Regards,
Ravi Chandra.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-07-2023 01:27 AM
This gets me the sys_id of the dept and unfortunately it only makes a new select option in the box with the sys_id. Any clue how to tell it to auto-fill the actuall user? Thank you so far tho
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-07-2023 01:54 AM
Ok so I found the solution to it.
By adding the following lines to the "Default Value" it auto-fills it with the right dept_head:
javascript:var userDept=gs.getUser().getDepartmentID();
var deptHead='';
var deptGR=new GlideRecord('cmn_department');
if(deptGR.get(userDept)){deptHead=deptGR.getValue('dept_head');}
deptHead;
Thanks again everyone nonetheless š
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-04-2023 08:54 AM
Hi,
There is the 'dept_head' field on cmn_department table that is a "Reference" to the sys_user table. there can only be one value there unless you change the field type to "List".