- 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-11-2024 06:07 AM
Thanks, I used Kilo Patron's solution, but yours also worked.
- 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 08:43 PM
Hi
In default Value just write below code
javascript:gs.getUserID()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 09:38 PM
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
Regards,
Shyamkumar