Auto-Populate name in Service Catalog using script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2023 04:03 AM
please help me with the script, after selecting 'other employee' for the variable 'request for' and selecting the user in 'who is the request for?', I would like it to complete my First Name and Last name.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2023 04:16 AM
@zuroslawski You need to create an onChange Script on the who_is_requested_for field. Script can be written as follows.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var requested_for = g_form.getReference('who_is_requested_for',callbackFunc);
function callbackFunc(caller){
g_form.setValue('first_name',caller.first_name);
g_form.setValue('last_name',caller.last_name);
}
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 07:08 PM
Hello@zuroslawski
you can write a simple onChange catalog client script to achieve this functionality.
here we go :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var requested_for = g_form.getReference('who_is_requested_for',callbackFunc);
function callbackFunc(caller){
g_form.setValue('fname',caller.first_name);
g_form.setValue('lname',caller.last_name);
}
}
for onLoad -use the below script .
function onLoad() {
g_form.setValue('fname',g_user.firstName);
g_form.setValue('lname',g_user.lastName);
}
for more info visit -
https://docs.servicenow.com/bundle/utah-application-development/page/script/client-scripts/concept/c...
Please mark my answer as "Accept as Solution" and "Helpful." If it works for you,
Regards
Vamsi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 08:06 PM
if you are on Utah and above you can use auto-populate feature and no scripting is required
Auto-populate a variable based on a reference type variable (Utah)
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 02:03 AM
HI @zuroslawski
You can use Auto Populate option in catalog.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************