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

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

View solution in original post

9 REPLIES 9

add one more alert statement after first line, need to check if code is triggering or not. same code is working on my PDI.

also make sure you are checking on the user where department value is filled. 

 

Hey,

 

Made sure to check on user with a department field that was populated. I can't seem to get a basic alert statement to run on the record from the UI Action. 

 

Since this is a new PDI, do you think it has something to do with the OOB configuration?

Never mind I got it to work!

Thanks for accepting the solution.

Please share 'why it was not working at first place'.

Harish KM
Kilo Patron

Hi @Philip Conforzi you can use the below code

  alert(g_form.getDisplayBox('department').value); // getDisplayBox will not work in Portal