- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 06:51 PM
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.
Also, the user must be active
Solved! Go to Solution.
- Labels:
-
Service Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 07:06 PM - edited 03-08-2024 07:09 PM
@EGUZMANHERRERA Here is the onLoad client script you need to create on your Catalog Item.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 08:42 PM - edited 03-08-2024 08:43 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 07:06 PM - edited 03-08-2024 07:09 PM
@EGUZMANHERRERA Here is the onLoad client script you need to create on your Catalog Item.
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 07:07 PM
Here Replace name of Catalog item with your Catalog item name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 06:08 AM
Thank you very much for the help, it worked perfectly!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 07:08 PM - edited 03-08-2024 07:16 PM
That should be easy, we did that.
In the Default Value tab.
Add this Javascript code.
You can also add a check to validate if user is active, I'm on my phone but will get more examples when I'm on the computer.
EDIT: actually it should work exactly like you want.
In the type specification tab, you add the filter to retrieve only active users.
And in the default value tab, the code to automatically populate the logged in user.
If my answer is correct, don't forget to mark it as solved/helpful. 😊