- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2016 11:01 AM
Hi all,
I am trying to set a reference variable (var = u_requested_for ref table = sys_user) on a record producer to the current user that opened it up. I believe this will need to be achieved through a Catalog Client Scripts, but for whatever reason it doesn't appear to be working. I am not a programmer, so my code may be/most likely is wrong. Any help or solutions would be greatly appreciated!
Catalog Client Scripts -
Name: Set request for variable
Applies to: A Catalog Item
Active: True
Type: onLoad
Applies on Cat Item view: True
Applies RITM: False
Applies on Cat Tasks: False
Script:
function onLoad() {
var userID = g_user.userID;
userID = g_form.setValue('u_requested_for');
}
I also tried g_form.setValue('u_requested_for',gs.getUserID()); but an error came up saying gs shouldn't be used in client scripts.
Thanks!
Niccole
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2016 11:05 AM
For the 3rd line of your script try
g_form.setValue('u_requested_for', userID);
Also, you could do this through the default value of the variable rather than a client script. Try this in the default value: javascript: gs.getUserID()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2018 05:50 AM
If you want to use the logged in user's manager as the default value I would just do:
javascript: gs.getUser().getManagerID();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2018 11:45 AM
Thanks for that Brad - I wasn't sure why I didn't try that one earlier... it works a treat.
BTW - I did get my other one working as well eventually late yesterday NZ time - what I got was below, but it's not as nice as your answer!
javascript: var user = new GlideRecord('sys_user'); user.get(gs.getUserID()); user.manager.sys_id;
Thanks for your help.
Carl.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2018 04:57 PM
Hi Brad,
The javascript bit was very helpful as I was doing this via a Client Script - Thanks!
I have an additional question - I have another variable on a record producer which requires me to grab the users manager - how would I be able to grab this value as a default using the above?
Thanks
Carl.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2020 06:40 AM
I would use this solution: How to auto populate with current user