Use UI Action to show department of user once their profile is selected on the user table

Philip Conforzi
Tera Contributor

Hello ServiceNow community.

 

I hope you're doing well.

 

I'm currently attempting to create a pop-up message showing a user's department in ServiceNow once their profile record is selected on the sys_user table.

 

I attached my solution below which I thought would give me the user's department, but is instead giving me their name.

 

If you have any insights on how to fix this, it would be most appreciated. 

 

PhilipConforzi_0-1707169978174.png

 

 

1 ACCEPTED SOLUTION

AshishKM
Kilo Patron
Kilo Patron

Hi @Philip Conforzi , 

Department is reference type field on User form, so its not giving the value via g_form.getValue('department');

Use the below code.

 

AshishKMishra_0-1707174834364.png

 

function showDept(){
var dept = g_form.getReference("department", displayDept);

function displayDept(dept){
alert("Department->"+dept.name);
}

}

AshishKMishra_1-1707174879291.png

 

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

View solution in original post

9 REPLIES 9

AshishKM
Kilo Patron
Kilo Patron

Hi @Philip Conforzi , 

Department is reference type field on User form, so its not giving the value via g_form.getValue('department');

Use the below code.

 

AshishKMishra_0-1707174834364.png

 

function showDept(){
var dept = g_form.getReference("department", displayDept);

function displayDept(dept){
alert("Department->"+dept.name);
}

}

AshishKMishra_1-1707174879291.png

 

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Hello,

Thanks for your solution!

I've tried it out but I can't seem to get the alert message to show up when I open a user record form the sys_user table.

Any thoughts??

Just confirming if you update the onClick field with the function name. highlighted in yellow in my previous reply.


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Hello,

Yes I updated it but wasn't able to see anything run. Please see the image I've pasted below to see my full UI action as it is now. Thanks again for your input, appreciate it!

PhilipConforzi_0-1707314595668.png