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

Are you using this in a scoped application (extension)? What version of ServiceNow? I may have a workaround based on those two factors.


This is not a scoped application and I am on Fuji.



Thanks


Hi Chad,



Don't worry about the JSON warning. It's bogus. JSON as a constructor



As for the other two properties. Do me a favor, put an alert line right after the var answer = to see what is being returned in your stringified object.



find_real_file.png


ok, added the alert.



Where will I find the output?


It should jump up in your face as soon as you change the user. If you're not seeing it, then something else is wrong on the server side that is causing it to abort. Welcome to the world of debugging client/server apps. 🙂



If you want to find out how far the server is getting, drop in some gs.log() statements and you can see them under System Logs> Script Log Statements.



I had to do this a bit last night to get the code running.