Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

I need help creating a catalog client scrip

nafiz435
Tera Contributor

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.
1 ACCEPTED SOLUTION

Its_Azar
Mega Sage

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 \

 

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.

Kind Regards,
Azar
Serivenow Rising Star
Developer @ KPMG.

View solution in original post

4 REPLIES 4

Its_Azar
Mega Sage

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 \

 

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.

Kind Regards,
Azar
Serivenow Rising Star
Developer @ KPMG.

Not applicable

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()); 
}

Not applicable

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);
}

T_Prashaanth
Mega Guru

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 - 

https://docs.servicenow.com/bundle/washingtondc-servicenow-platform/page/product/service-catalog-man... 

 

Please mark my answer as helpful if it is correct