The CreatorCon Call for Content is officially open! Get started here.

Auto Populate user's email on catalog item field

pathumh09586800
Mega Contributor

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?

19 REPLIES 19

Ravi Gaurav
Giga Sage
Giga Sage

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/
Hi Youtube Family, I am Ravi Gaurav. I am Expert in ServiceNow . Welcome to my youtube channel. If you guys enjoyed it, make sure to Like👍 , Comment💬 and Subscribe❤️ _________________________________________ Copyright Disclaimer : All Rights to VideoLabel Co. & No Copyright infringement intende...

Ravi Gaurav
Giga Sage
Giga Sage

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.

 

 
function onLoad() {
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/

Ankur Bawiskar
Tera Patron
Tera Patron

@pathumh09586800 

you can use default value like this in variable and no other scripting required

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

 

AnkurBawiskar_0-1758095338732.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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.

 

T_Mia_0-1758111336718.png

 

Appreciate your valuable advice.