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

@Abbottronix Could you please confirm if u_requestor is a reference to sys_user table or not? 

@Abbottronix Also check if there is any reference qualifier defined on the Affected Contact field which might be allowing only selected records on that field.

Hi Sandeep,

 

The u_requestor field references sys_user yes. Karan Chhabra6 helped solve part of the problem by suggesting using ('caller_id', requestor.sys_id), although I don't understand why that works. 

Harish Kota
Kilo Sage

Hi @Abbottronix 

 

Use Script Include and Client script for this requirement like below.

 

Client Script:
-------------------
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

//Type the appropriate comment here, and begin the script below
var ga = new GlideAjax('GetCallerDetails');
ga.addParam('sysparm_name', 'getDetails');
ga.addParam('sysparm_caller', newValue);
ga.getXML(callback);
function callback(response)
{
var answer=response.responseXML.documentElement.getAttribute("answer");
var result=answer.split(";");
g_form.setValue("caller_id", result[0]);
g_form.setValue("u_company", result[1]);

}
}

Script Include
--------------
var GetCallerDetails = Class.create();
GetCallerDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getDetails:function()
{
var caller=this.getParameter('sysparm_caller');
var gr= new GlideRecord('sys_user');
gr.addQuery('sys_id',caller);
gr.query();
if(gr.next())
{
return gr.caller+";"+gr.company;
}
},
type: 'GetCallerDetails'
});

 

Please don't use getReference method, it is not a good practice.

Please hit like or Accept as solution if it will works for you.

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!