We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

On demo catalog item, populate the phone number and email of current user from the user table.

pk16514
Tera Contributor

How to solve the above problem, using client script methods g_form and g_user only

2 ACCEPTED SOLUTIONS

Maik Skoddow
Tera Patron

Hi @pk16514 

it's not recommended to do this on client-side as the code might not work in all experiences. Instead, do this in the catalog item. The following article explains how to do that: https://blog.snowycode.com/post/how-to-auto-populate-the-current-user-in-servicenow

Maik

View solution in original post

VaishnaviShinde
Kilo Sage

Hello @pk16514 ,

 

Instead of using client script. You can populated email and phone number by using default value.

Add below in default value to that variables :

javascript:gs.getUser().getRecord().getValue('phone_number');//phone number

javascript:gs.getUser().getRecord().getValue('email');//email

 

Please Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

 

Regards,

Vaishnavi Shinde

 

View solution in original post

5 REPLIES 5

Maik Skoddow
Tera Patron

Hi @pk16514 

it's not recommended to do this on client-side as the code might not work in all experiences. Instead, do this in the catalog item. The following article explains how to do that: https://blog.snowycode.com/post/how-to-auto-populate-the-current-user-in-servicenow

Maik

Thanks @Maik Skoddow . Actually I am practicing scripting that's why wanted to use client script. Thanks for the response. Helpful article and feedback.

VaishnaviShinde
Kilo Sage

Hello @pk16514 ,

 

Instead of using client script. You can populated email and phone number by using default value.

Add below in default value to that variables :

javascript:gs.getUser().getRecord().getValue('phone_number');//phone number

javascript:gs.getUser().getRecord().getValue('email');//email

 

Please Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

 

Regards,

Vaishnavi Shinde

 

PPPanchal
Mega Sage

Hello @pk16514 ,

1)Add below code to the default value of the variable for populating Email:

javascript:gs.getUser().getEmail();

 

Pratiksha_PP_0-1704260389345.png

 

2)Add below code to populate Phone Number : 

javascript: var userPhone; var user = new GlideRecord('sys_user'); if (user.get(gs.getUserID())) {userPhone = user.mobile_phone}; userPhone;

 

Pratiksha_PP_1-1704260462580.png

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Please mark correct/helpful if this helps you!
Thanks,
Pratiksha
✨ServiceNow Rising Start 2025