onChange Cient Script causing "Match not found, reset to original" error

Abbottronix
Tera Guru

I've created the following onChange client script to automatically set the Caller Id and custom Company field on incidents. 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

	g_form.getReference('u_requestor', setContact);
	}

	function setContact(requestor) {
		if (requestor && requestor.company != '')
			g_form.setValue('caller_id', requestor.name);
			g_form.setValue('u_company', requestor.company);
	}

When I try to submit a new incident it gives me the error "Invalid update" and "Match not found, reset to original". When I try to change the company of an existing incident and then update the incident, my update to the company field isn't saved. 

 

 

1 ACCEPTED SOLUTION

Karan Chhabra6
Mega Sage
Mega Sage

Hi @Abbottronix ,

 

Please use this script, it should work

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

	g_form.getReference('u_requestor', setContact);
	}

	function setContact(requestor) {
		if (requestor && requestor.company != '')
			g_form.setValue('caller_id', requestor.sys_id);
			g_form.setValue('u_company', requestor.company);
	}

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!

 

View solution in original post

12 REPLIES 12

Sandeep Rajput
Tera Patron
Tera Patron

@Abbottronix Caller_id is a reference field and it expects a sys_id. Change your script as follows.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

	g_form.getReference('u_requestor', setContact);
	}

	function setContact(requestor) {
		if (requestor && requestor.company != '')
			g_form.setValue('caller_id', requestor);
			g_form.setValue('u_company', requestor.company);
	}

Hope this helps.

Hi Sandeep,

 

When I make this change, the Affected Contact (called_id) field no longer gets autofilled. It stops being mandatory, as though it had been filled, but there's nothing actually in the field.

@Abbottronix Try the following version.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

	g_form.getReference('u_requestor', setContact);
	}

	function setContact(requestor) {
		if (requestor && requestor.company != '')
			g_form.setValue('caller_id', requestor,requestor.name);
			g_form.setValue('u_company', requestor.company);
	}

This time it should work.

Hi Sandeep,

 

The field is now autofilling as hoped, but now the original problem has returned: 

 

attempt2.PNG