- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2024 05:51 PM
Hi, I am learning service now, please help me out
This is my client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var caller_details = g_form.getValue('caller_id');
alert(caller_details);
var ga = new GlideAjax('getEmailID');
ga.addParam('sysparm_name', 'emaildetails');
ga.addParam('sysparm_value', 'caller_details');
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
}
And this is my script include
var getEmailID = Class.create();
getEmailID.prototype = {
emaildetails: function() {
var test = this.getParameter('sysparm_value');
var x = new GlideRecord('sys_user');
x.addQuery('sys_id', test);
x.query();
if (x.next()) {
return x.email;
}
},
type: 'getEmailID'
};
When I run this in Incident table, it is giving me null response in the second alert in the client script
Please help me
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2024 07:18 AM
Hi @MohdF
There are a few mistakes in you client script and script include.
In you client script you are passing caller_details as a string not a variable.
Here is an updated version of the client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var caller_details = g_form.getValue('caller_id');
var ga = new GlideAjax('getEmailID');
ga.addParam('sysparm_name', 'emaildetails');
ga.addParam('sysparm_value', caller_details); // Corrected line
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
}
In you script include you have the make sure its client callable (checkbox) and make sure in you prototype you extend AbstractAjaxProcessor.
Here is an update version of the script include:
var getEmailID = Class.create();
getEmailID.prototype = Object.extendsObject(AbstractAjaxProcessor, {
emaildetails: function() {
var test = this.getParameter('sysparm_value');
var x = new GlideRecord('sys_user');
x.addQuery('sys_id', test);
x.query();
if (x.next()) {
return x.email;
}
return '';
},
type: 'getEmailID'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2024 07:18 AM
Hi @MohdF
There are a few mistakes in you client script and script include.
In you client script you are passing caller_details as a string not a variable.
Here is an updated version of the client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var caller_details = g_form.getValue('caller_id');
var ga = new GlideAjax('getEmailID');
ga.addParam('sysparm_name', 'emaildetails');
ga.addParam('sysparm_value', caller_details); // Corrected line
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
}
In you script include you have the make sure its client callable (checkbox) and make sure in you prototype you extend AbstractAjaxProcessor.
Here is an update version of the script include:
var getEmailID = Class.create();
getEmailID.prototype = Object.extendsObject(AbstractAjaxProcessor, {
emaildetails: function() {
var test = this.getParameter('sysparm_value');
var x = new GlideRecord('sys_user');
x.addQuery('sys_id', test);
x.query();
if (x.next()) {
return x.email;
}
return '';
},
type: 'getEmailID'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2024 10:35 AM
It worked, thank you but when I opened that script include initially when I was about to write the code it doesn't gave me snippet that's why it was giving me null response, but thank you again.
Object.extendsObject(AbstractAjaxProcessor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2024 10:41 AM
It worked, but when I opened getEmailID script include initially when I was about to write the code it didn't give me the object.extendsObject(AbstractAjaxprocessor snippet, I thought that is because of the version or something but when I applied it worked, anyways thank you again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2024 07:25 AM
Few things to highlight
1) your script include seems not to be client callable, please correct that
2) is script include and client script in same scope
try the script shared by other community member and let us know the updates.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader