- 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
- 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