Display read only information about a user

phil34
Tera Expert

Hi There,

Catalog Item Form

I have a use case where I need to retrieve and display information based on looking up a user in the sys_user table.

Not all the information is in the sys_user table but it is in related tables in some way mostly in the cmn_location table via another reference.

I need the information to change or update as soon as the user is selected so it can be displayed.

EG If user John Smith Is selected I need the location name assigned against John smith to appear below the user name as a default value in a read only variable. Then based on the location name that appears in that variable I need the division assigned to that location to appear in another variable field. Then the next variable field would be the Phone Number in the location table.

If another user is selected i.e. the user David Brown is selected then I want the above variable fields to update with the location details for David Brown.

In this use case all the returned details would be unique to the user and already values assigned to existing fields so I am not looking for an array of values just the actual values that are assigned to the fields I need to display.

Hopefully that makes sense and hoping someone can help.

P.S. I have had some success so far in that I can display and update the location of the selected user however the next hop to retrieving the additional information from the location table is where I am stuck.    

5 REPLIES 5

Ct111
Giga Sage

Check below thread for reference.

LINK

It has the example of location you are looking for.

Whatever, extra fields you need add it to the code accordingly

 

Mark my ANSWER as CORRECT and hELPFUL if it helps

phil34
Tera Expert

Hi Creativethinker,

Thanks for the reply but I am not sure this is what I need.

Basically what I am after is this

I provide a user name from the drop-down reference filed to the sys_user Table

From that, I look up the location of that user which is also in the sys_user Table

The next part is where I get stuck. I can now see the location of the user so I want to get the next value in the next field which is from the cmn_location Table. so if it was a dot walk it would be something like

getslecteduser().getlocation().getdivision(); where location is a field stored in sys_user but the division is a field stored in cmn_location

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

why not write 1 onChange client script + GlideAjax script include and fetch all the details for that user at once and return it from script include function

you can bring in the user's location, department etc and then for every user change you can set the value in those other variables and make them readonly

check this GlideAjax syntax on how to fetch multiple values

Get User Details based on the Logged in user/ User selected in Client Script

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

Sorry I am new at Service Now and not great at scripting. I might be missing something but it seems you are saying that all the user information is in the sys_user table but it is not.

When a user is selected I can show the location in a read-only field using a catalogue Client Script.

The issue I have is that the next field I want to display is Division. The division is on the Location record, not the User Record.

Hopefully, some screenshots will assist?

This is the form I am testing with.

find_real_file.png

Here is the catalog Client script that works for the location field. Note the location value is on the user record.

find_real_file.png

This is the catalogue Client Script I have for the Division (Not Working) Note the division value is on the Location Record

find_real_file.png

This is the form when I select a user. Note the Division should change each time the location changes and the location should change based on the user selected.

find_real_file.png

It would be great if you could guide me in detail about what I need to do here then I will be able to extend that to other tables and fields that I need for the use case.