The CreatorCon Call for Content is officially open! Get started here.

Auto-populate field on Cat Item Form with "Head of Department" of Users department

Konstantinos Di
Mega Guru

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 šŸ™‚

1 ACCEPTED SOLUTION

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 šŸ™‚

View solution in original post

5 REPLIES 5

Ravi Chandra_K
Kilo Patron
Kilo Patron

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.

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

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 šŸ™‚

Bert_c1
Kilo Patron

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".