Harish Bainsla
Kilo Patron

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

Gunjan Kiratkar
Kilo Patron

Hi @Hm10 ,

 

The syntax you shared in the question description for default value works well in my instance.

 

GunjanKiratkar_0-1693068596657.png

 

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

SN_Learn
Kilo Patron

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:
Screenshot 2023-08-26 221613.png

 

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.

Sohithanjan G
Kilo Sage

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 🙂

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

Gaurav Shirsat
Mega Sage

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

View solution in original post