Auto Populate user's email on catalog item field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I’m creating a Service Catalog item and I have a variable to capture the requester’s email. How can I automatically populate this variable with the logged-in user’s email when the form loads?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @pathumh09586800
Its easy one.. Let me send you the video:
the below will help
https://www.youtube.com/watch?v=4unHkSkkT70&list=PLKH9bPqlw1neGCJbunoZl7ag-zYxyi8Oe&index=7
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @pathumh09586800
You can use the below Sample Code As well
Create a Script Include
-
Name: GetUserInfo
-
Check Client Callable = true.
var GetUserInfo = Class.create();
GetUserInfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserEmail: function() {
var userId = gs.getUserID(); // logged-in user sys_id
var gr = new GlideRecord('sys_user');
if (gr.get(userId)) {
return gr.getValue('email'); // return the email address
}
return '';
}
});
Create a Catalog Client Script
-
Type: onLoad
-
Applies to: your catalog item.
var ga = new GlideAjax('GetUserInfo');
ga.addParam('sysparm_name', 'getUserEmail');
ga.getXMLAnswer(function(response){
var email = response;
g_form.setValue('requester_email', email);
});
}
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
you can use default value like this in variable and no other scripting required
javascript: gs.getUser().getEmail();
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
3 weeks ago
Hi Ankur,
Under which variable name did you include this script.
I'm trying to create a simple request form where I want the email field to be automatically populated when a name is selected in the name field.
Currently my name field is a reference field and email field is a read only single line text. See screen print.
Appreciate your valuable advice.