- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2022 01:44 PM
I want to set the email and manager of the caller. I have written script Include and then called that in my client script but it is giving me the error, "onChange script error: ReferenceError: answer is not defined function () { [native code] }" below the caller field but its working correctly. I wanted to know why it the error is coming? Thank you so much for the help!
Script Include:
var setEmailandManager = Class.create();
setEmailandManager.prototype = Object.extendsObject(AbstractAjaxProcessor, {
populateEmailAndManager: function()
{
var userID = this.getParameter('sysparm_user');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',userID);
gr.query();
if(gr.next())
{
var obj = {};
obj.email = gr.email;
obj.manager = gr.manager;
return JSON.stringify(obj);
}
},
type: 'setEmailandManager'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('setEmailandManager');
ga.addParam('sysparm_name','populateEmailAndManager');
ga.addParam('sysparm_user',newValue);
var obj = JSON.parse(answer);
g_form.setValue('email',obj.email);
g_form.setValue('manager',obj.manager);
}
Solved! Go to Solution.
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2022 01:53 PM
Hi,
Thats because the answer variable is not defined. the following line is missing.
var response = ga.getXMLAnswer(parseResponse);
function parseResponse(answer) {
var obj = JSON.parse(answer);
g_form.setValue('email',obj.email);
g_form.setValue('manager',obj.manager);
}
Mark the comment as a correct answer and helpful if this has answered the question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2022 01:53 PM
Hi,
Thats because the answer variable is not defined. the following line is missing.
var response = ga.getXMLAnswer(parseResponse);
function parseResponse(answer) {
var obj = JSON.parse(answer);
g_form.setValue('email',obj.email);
g_form.setValue('manager',obj.manager);
}
Mark the comment as a correct answer and helpful if this has answered the question.