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.

Populate caller's location on Incidents

Not applicable

Very simple client script set to onChange of the Incident Caller field. When the caller is set or changed, the incident location is updated if the caller has a location specified on their profile.

=================================

function onChange(control, oldValue, newValue, isLoading) {
if (oldValue == newValue) {
return;
}

var caller = g_form.getReference('caller_id');

if (caller.location) {
g_form.setValue('location', caller.location);
}
}

5 REPLIES 5

Hi,

Try this edited code and this should work.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}
	
	var caller = g_form.getReference('caller_id');
	
	if (caller.location) {
		var grLoc = new GlideRecord('cmn_location');
		grLoc.addQuery('sys_id', caller.location);
		grLoc.query();
		if(grLoc.next())
			g_form.setValue('short_description', grLoc.name);
	}
}

Make sure you have given Field name as Caller.

Mark the answer as Correct/Helpful based on its impact.

Thanks,

Archana