Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Get the email from requested for field

NelishaJ
Tera Contributor

I want to fetch the email of the user i select in the requested for field. How to do this?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@NelishaJ 

you can use onchange client script and use getReference with callback

something like this

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading) {
		return;
	}
	if(newValue == ''){
		g_form.clearValue('email');	// email variable name here
	}

	var ref = g_form.getReference('requested_for', callBackMethod);	// requestedFor variable name
}

function callBackMethod(ref){
	if(ref.email)
		g_form.setValue('email', ref.email); // email variable name here
}

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

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@NelishaJ 

you can use onchange client script and use getReference with callback

something like this

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading) {
		return;
	}
	if(newValue == ''){
		g_form.clearValue('email');	// email variable name here
	}

	var ref = g_form.getReference('requested_for', callBackMethod);	// requestedFor variable name
}

function callBackMethod(ref){
	if(ref.email)
		g_form.setValue('email', ref.email); // email variable name here
}

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

This code really helped. Thank you for sharing 🙂

Ankur Bawiskar
Tera Patron
Tera Patron

@NelishaJ 

use this and no script is required

Auto-populate a variable based on a reference type variable (Utah) 

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