How to auto populate the First Name, last name and email of the user in the service catalog

Chandramouli
Tera Contributor

Hi Team,

Any one can explain the, How to Populate First Name, Last Name  and email address in catalog form from user table.

 

Actually I am new to scripting, I create catalog item and created variable name FullnameI( referance field Sys_user table) and First Name and Last name are single text line and email address

I want, if i enter full name from the user table, the first name and last name and email address should auto populated.

 

Please help me, how can i do this 

3 REPLIES 3

John Longhitano
Kilo Guru

I would use a combination of a client script and a glideajax call that way it works on both desktop and service portal view.  An example can be found here.  It looks quite tricky at first but once you get an example working it's not so bad.

https://community.servicenow.com/community?id=community_article&sys_id=9f7ce2e1dbd0dbc01dcaf3231f961...

Narendra Kota
Mega Sage

you can also use callback function in OnChange client script.

Make sure the field names (user table) and variable names are correct.

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
	
	var user =  g_form.getReference('Fullname', popUserDetails);
	
	function popUserDetails(user){
		
		g_form.setValue('firstnamevariable', user.first_name);
		g_form.setValue('lastnamevariable', user.last_name);
		g_form.setValue('emailvariable', user.email);
			
	}
}

 

Hope this helps.
Mark helpful or correct based on impact.

Thanks.

 

I think we have to be careful with recommending getReference() since it pulls the entire user record instead of only the fields / information required.  ServiceNow recommends GlideAjax instead.