- 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
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
01-05-2016 02:08 PM
Thanks Brad! I tried the default value first and that did the trick .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2016 05:21 AM
Great. Default is definitely the better way to go as your doing everything server side as the form loads.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2018 05:38 PM
Update on my last post - I have the code below working on a 'multi line text' variable to grab the users manager:
javascript: var user = new GlideRecord('sys_user'); user.get(gs.getUserID()); user.manager;
However when I use the same default value on my reference field it isn't working. I'm aware a reference field looks at the sys_id, but not sure how to change the value into the sys_id so it display correctly?
Essentially I want to default the value, but if their manager had changed recently than the users need the ability to select their new manager. This is why it needs to be a reference field as I'll then also use this value to input into the workflow approvals to ensure the right person is sent the approval.
Thanks
Carl.