Auto populate "requested for" email id and manager

karunasrikuna
Tera Contributor

Hi , 

 

I am working on creating a catalog item , I want to auto populate the email address field and manager field based on "Requested for" field. How can we achieve this. Any help would be appreciated.

 

Thanks,

Karuna.

 

 

6 REPLIES 6

Jitendra Diwak1
Kilo Sage

Hi @karunasrikuna,

 

You can help with this below thread:

https://www.servicenow.com/community/guided-learning-itsm/i-want-to-auto-populate-the-user-details-b...

 

https://www.servicenow.com/community/developer-forum/autopopulate-user-details-onchange-of-user-name...

 

Note: email variable should be reference one, it should be string type and try to visible false.

 

Please accept my solution if it works for you and thumps up.

 

Thanks

Jitendra

Please accept my solution if it works for and thumps up.

Vasantharajan N
Giga Sage
Giga Sage

@karunasrikuna - We have the OOTB feature in the variable form under the section "Auto Populate". Please refer to the screenshot that helps you to auto populate the value based on the reference field in your catalogue item.

 

VasantharajanN_0-1717744808797.png

 

More information from documentation : https://docs.servicenow.com/bundle/washingtondc-servicenow-platform/page/product/service-catalog-man...


Thanks & Regards,
Vasanth

dgarad
Giga Sage

Hi @karunasrikuna 

You can achieve this by creating an onChange catalog client script and client callable script include.

// OnChange client script, should run on change of Requested for Variable

var ga = new GlideAjax('Script Include name'); 
	ga.addParam('sysparm_name','getUserDetails'); 
	ga.addParam('sysparm_userId', g_form.getValue('requested_for'); //type correct name of your variable. 
	ga.getXML(ResponseFunction); 
	
	function ResponseFunction(response) { 
		var answer = response.responseXML.documentElement.getAttribute("answer"); 
		var results = JSON.parse(answer);
        g_form.setValue('firstName',results.firstName);
        g_form.setValue('lastName',results.lastName);
        g_form.setValue('manager',results.manager);
        g_form.setValue('email',results.email);
        g_form.setValue('title',results.title);
	}



//Script Include
getUserDetails: function() {
	var userID = this.getParameter('sysparm_userId');
		var user = new GlideRecord('sys_user');
		user.get(userID);
		var obj ={};
		obj.firstName = user.first_name;
		obj.lastName = user.last_name;
		obj.manager = user.manager;
		obj.email = user.email;
		obj.title = user.title;
		return JSON.stringify(obj);
    }
If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Astik Thombare
Tera Sage

Hi @karunasrikuna ,

 

Please refer below thread -

 

https://www.servicenow.com/community/guided-learning-itsm/how-to-auto-populate-manager-email-id-base...

 

      If my reply helped with your issue please mark helpful 👍 and correct ✔️ if your issue is resolved.

 

                         By doing so you help other community members find resolved questions which may relate to an issue they're having

 

 

Thanks,

 

Astik