Autopopulate field in a catalog using Client Scripts

EGUZMANHERRERA
Tera Contributor

Hi everyone, I want to use Clients Scripts to autopopulate the "Requested By: " field with the name of the user who is making the request in the catalog, The field is set as Read Only because I want the Client Script to autopopulate without user intervention. Can anyone please help me, I'm new using ServiceNow so my knowledge is very limited. Request By.png

Also, the user must be active

Type specifications.png

2 ACCEPTED SOLUTIONS

Sandeep Rajput
Tera Patron
Tera Patron

@EGUZMANHERRERA Here is the onLoad client script you need to create on your Catalog Item.

 

Screenshot 2024-03-09 at 8.38.33 AM.png

 

Here is the script.

 

 

function onLoad() {
    //Type appropriate comment here, and begin script below    
	g_form.setValue('requested_by',g_user.userID);

}

 

 

Hope this helps.

View solution in original post

Sumanth16
Kilo Patron

Hi @EGUZMANHERRERA ,

 

Configure onload catalog client script and use below code:

 

g_form.setValue('requested_for',g_user.userID);// replace variable with your variable name

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda

View solution in original post

8 REPLIES 8

Thanks, I used Kilo Patron's solution, but yours also worked.

Sumanth16
Kilo Patron

Hi @EGUZMANHERRERA ,

 

Configure onload catalog client script and use below code:

 

g_form.setValue('requested_for',g_user.userID);// replace variable with your variable name

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda

Harish Bainsla
Kilo Patron
Kilo Patron

Hi 

In default Value just write below code

javascript:gs.getUserID()

shyamkumar VK
Kilo Patron

Hi @EGUZMANHERRERA  , Instead of Client Script , you can utilize Default Value and add this piece into the Variable default Value

 

javascript:gs.getUserID()

 

Regards,

Shyamkumar

 

Please mark this as helpful and accept as a solution if this resolves your Ask.
Regards,

Shyamkumar