How to autopopulate catalog item variables using sys_user table

User163016
Tera Contributor

I have a request form that needs to auto populate 4 variables based on the user that opened the request.   The 4 fields are Project owner name, title, department and phone.   These are all fields that exist in the sys_user table.   I read through several discussions and found different variations on how to accomplish this, some of them with catalog client scripts but so far I have been unsuccessful with these suggestions.   Bhavesh Jain did suggested in a post to use javascript:gs.getUser().getFullName() in the default value field for name and that worked perfectly, but I'm unable to figure out how to get this to work for the other three fields.   Any help is appreciated.

Thanks,

1 ACCEPTED SOLUTION

Hi Chad,



I've attached a simple script include and client script that should do the job for you. You will   need to update the catalog client script to the right Catalog Item.



Check the field variable names, but I think you'll find it's all there.


View solution in original post

24 REPLIES 24

Chuck Tomasi
Tera Patron

Hi Chad,



My recommendation is to write an onChange client script (that also runs at onLoad) to do a GlideAjax call and retrieve all those attributes from the server. Accessing this information on the server is easy once you have the user ID which is passed from the client. The server processes the request and passes back the information in a JSON object that the client can then parse and put in the various fields.



GlideAjax - ServiceNow Wiki


Hi Pradeep,



FYI - Just a footnote, there may be performance issues with that solution you cited. It looks like it does a server call for each field to retrieve an entire record (sometimes 2X/record - one for the sys_id and one for the display value.) A GlideAjax solution would make one server call for all bits.


Thank you Chuck. I have responded with GlideAjax in my earlier response and I agree that is the best solution.


The confusion seems to be with the correct answer marked there.