- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 10:38 AM
I need help creating a catalog client script in ServiceNow to fetch the logged-in user's details, including their username, email address, and phone number, and display these in the respective fields on the form.
- Automatically populate the form fields with the logged-in user's details.
- Fields to be populated: Username, Email Address, and Phone Number.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 10:40 AM
Hi there @nafiz435 \\
Give
function onLoad() {
var user = g_user.userName;
var email = g_user.email;
var phone = g_user.phone;
// Populate form fields with user details
g_form.setValue('username_field', user);
g_form.setValue('email_field', email);
g_form.setValue('phone_field', phone);
}
this a try \
Kind Regards,
Mohamed Azarudeen Z
Developer @ KPMG
Microsoft MVP (AI Services), India
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 10:40 AM
Hi there @nafiz435 \\
Give
function onLoad() {
var user = g_user.userName;
var email = g_user.email;
var phone = g_user.phone;
// Populate form fields with user details
g_form.setValue('username_field', user);
g_form.setValue('email_field', email);
g_form.setValue('phone_field', phone);
}
this a try \
Kind Regards,
Mohamed Azarudeen Z
Developer @ KPMG
Microsoft MVP (AI Services), India
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 10:43 AM
function onLoad() {
var user = gs.getUser(); // Get the current user's details
g_form.setValue('username', user.getUserName());
g_form.setValue('email_address', user.getEmail());
g_form.setValue('phone_number', user.getPhone());
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 11:41 AM
function onLoad() {
// Fetch logged-in user's details
var user = g_user;
// Set the value of fields with the logged-in user's details
g_form.setValue('username_field', user.name);
g_form.setValue('email_address_field', user.email);
g_form.setValue('phone_number_field', user.phone);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 01:53 PM
Hi @nafiz435 we dont need to create a catalog client script to auto populate this, we have auto populate tabs available . Please refer the documentation below -
Please mark my answer as helpful if it is correct