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

I'm afraid I may be in way over my head and will need help with that script if you don't mind?   My fields are:


sys_user             Variable


title                                 po_title


department       po_dept


phone                       po_phone



I'm looking through the script that Pradeep had provided in the previous post and I think that's where I got lost when I originally started researching this.


I'm a little confused on why this would be onChange instead of onSubmit?


Hi Chad,



Can I ask a simple question... why are you not just dot-walking to this information after the request is submitted?



For example. current.variables.user.department



Will the department/phone/title ever be different than the one found on the user's profile?


Hi Chuck,   The requirement is the information be populated and can be updated.   This will help maintain the integrity of the user table but allow the users flexibility to update the information if necessary for this request.



Thanks for the scripts, I'm hoping to get to them right away.



Thanks!!


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.


Hi Chuck,



I have installed the scripts and confirmed all the variable names are correct.   I also confirmed that the catalog client script is pointed to the correct catalog item.   I ran my first test and the title field did populate, however phone and department did not.   I played around with it a bit and couldn't get those two fields to populate.   I ran a check syntax on the script include and got a warning message: Do not use JSON as a constructor on the following line: var answer = new JSON().encode(uObj);



Any ideas?



Thanks,