- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2024 09:20 PM
How to solve the above problem, using client script methods g_form and g_user only
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2024 09:25 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2024 09:33 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2024 09:25 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2024 09:30 PM
Thanks @Maik Skoddow . Actually I am practicing scripting that's why wanted to use client script. Thanks for the response. Helpful article and feedback.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2024 09:33 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2024 09:42 PM - edited ‎01-02-2024 09:43 PM
Hello @pk16514 ,
1)Add below code to the default value of the variable for populating Email:
javascript:gs.getUser().getEmail();
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;
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.