- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2023 07:15 AM
HI everyone !
I am trying to autopopulate a field name requested_by type reference to sys_user table with the current logged in user.
I have created a Catalog Client Script with this code.
function onLoad() {
// Get the current logged-in user
var currentUser = GlideUser.getUser();
// Get the field element you want to autofill
var fieldA = g_form.getControl('requested_by'); // Replace 'field_a' with the actual field name
// Set the value of Field A to the current user's name
fieldA.setValue(currentUser.getFullName());
}
But this gives me ID instead.
I have also set defaultvalue with javascript:gs.getUserID();. Both of them are not working. What am I doing wrong ?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2023 08:48 PM
Hello @Hm10
is this a Catalog Item Variable or Record Producer Variable?
It should suffices by setting default value of your requested_by variable as javascript:gs.getUserID();
if you are in Record Producer then in the Script Section try producer.requested_by=gs.getUserID();
Thanks and Regards
Gaurav Shirsat

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2023 07:25 AM
Hi,
Try using javascript: gs.getUser();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2023 08:01 AM
Hi,
Please try
g_form.setValue('requested_by',g_user.getUserID());
or
fieldA.setValue(g_user.getUserID());
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2023 08:10 AM
Hi
Make client script inactive and keep default value of requested by field as javascript:gs.getUserID()
Thanks,
Ramya Addala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2023 09:10 AM
Try thi s
function onLoad() {
var currentUser = GlideUser.getUser();
var fieldA = g_form.getValue('requested_by');
fieldA.setValue(currentUser.getID());
}
if you get answer please mark helpful and accept solution