- 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 09:52 AM
Hi @Hm10 ,
The syntax you shared in the question description for default value works well in my instance.
You can try checking if there are any other catalog client scripts or UI policy might be clearing that value.
Please let me know if anything else is needed.
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2023 09:56 AM
Hi @Hm10 ,
Please follow the steps below to populate the logged-in user in a reference field:
1. Right-click on the field and navigate to 'configure dictionary > go to the default value and type as below:
2. The second way to setup the same in catalog item is explained in the below link:
Get User Details based on the Logged in user/ User selected in Client Script
Please accept my answer and mark this helpful if it helps.
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2023 10:19 AM - edited 08-26-2023 10:22 AM
Hi @Hm10,
If you want the client script to set logged-in user value use the below syntax
function onLoad() {
g_form.setValue('req_for',g_user.userID);
}
OR simply you can use g_form.setValue('req_for',g_user.userID); anywhere in client side.
For server side: javascript:gs.getUserID(); in the default value
Please mark as Accepted Solution & Helpful 🙂

- 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