- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 07:42 AM
I am having an issue in calling a script include:
Catalog Client Script:
var TotalSmsGA = new GlideAjax('EmploymentUtils');
TotalSmsGA.addParam('sysparm_name', '_getTotalSMS');
TotalSmsGA.getXML(getSMSLength);
function getSMSLength(response) {
var test = response.responseXML.documentElement.getAttribute("answer");
console.log(test);
}
Script Include:
_getTotalSMS: function() {
return '100';
},
SI is client callable.
I am getting the result as null. Any suggestions for what is wrong here?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 08:19 AM - edited 05-15-2024 08:20 AM
Hi @vidhya_mouli,
Use the following tried and tested on my PDI (leveraging a random onLoad Client Script and Cat Item):
I'm alerting the result of 100 so you can confirm it's working. You'll just need to assign that to whatever variable or use appropriately for your use case.
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var TotalSmsGA = new GlideAjax('EmploymentUtils');
TotalSmsGA.addParam('sysparm_name', 'getTotalSMS');
TotalSmsGA.getXML(getSMSLength);
function getSMSLength(response) {
var test = response.responseXML.documentElement.getAttribute("answer");
alert(test);
}
}
Script Include:
var EmploymentUtils = Class.create();
EmploymentUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getTotalSMS: function() {
return '100';
},
type: 'EmploymentUtils'
});
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 08:06 AM - edited 05-15-2024 08:09 AM
Try a function name without the leading _ / special character. Do you happen to have more than one SI with the same name? Is the SI in the same application/scope as the Catalog Item / Catalog Client Script? If not, use the scope name in the GA call:
var TotalSmsGA = new GlideAjax('global.EmploymentUtils');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 08:06 AM
try without "_"
getTotalSMS
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 08:19 AM - edited 05-15-2024 08:20 AM
Hi @vidhya_mouli,
Use the following tried and tested on my PDI (leveraging a random onLoad Client Script and Cat Item):
I'm alerting the result of 100 so you can confirm it's working. You'll just need to assign that to whatever variable or use appropriately for your use case.
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var TotalSmsGA = new GlideAjax('EmploymentUtils');
TotalSmsGA.addParam('sysparm_name', 'getTotalSMS');
TotalSmsGA.getXML(getSMSLength);
function getSMSLength(response) {
var test = response.responseXML.documentElement.getAttribute("answer");
alert(test);
}
}
Script Include:
var EmploymentUtils = Class.create();
EmploymentUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getTotalSMS: function() {
return '100';
},
type: 'EmploymentUtils'
});
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie