- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 12:31 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 01:05 AM
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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 01:28 AM
@Abbottronix Could you please confirm if u_requestor is a reference to sys_user table or not?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 01:36 AM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 03:29 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 01:00 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2023 01:05 AM
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!