Issue with Script Include function call
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 06:08 AM
Hi All,
Requirement is based on change of assigned to, I need to display count of incidents assigned to the selected assigned to.
I had used onChange client script and Script include, but I am getting null value.
When I tried to debug using script debugger, logs, the function written inside script include is not getting executed.
I have provide admin role for the execute ACL for the script include, also it is client callable.
Below is the code-
Client script-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 06:13 AM - edited 12-07-2023 06:26 AM
Hi Rose,
Good job on the attempt and logging to troubleshoot. The function is not getting executed because GlideAjax must use sysparm_name to identify the function
sc.addParam('sysparm_name', 'getCount');
Once the function is getting called, if you are still not getting expected results, your logs, and others that you add, will help show where there is a typo or logic/syntax issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 08:47 PM
It is working now. But when I try to display the message in the client script using-
Instead of assigned to name, it is showing incident number.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 06:22 AM - edited 12-07-2023 06:22 AM
Hi @Rose17,
As Brad pointed out you need to use the sysparm_name to identify your function and I also noticed a typo in the Script Include:
Instead of this.getParamater('sysparm_value');, it should be this.getParameter('sysparm_value');
Client:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var sc = new GlideAjax('getIncidentCount');
sc.addParam('sysparm_name', 'getCount'); // Change 'sysparm_func' to 'sysparm_name'
sc.addParam('sysparm_value', g_form.getValue('assigned_to'));
sc.getXML(getResponse);
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
g_form.addInfoMessage('Count of Incidents: ' + answer);
}
}
SC:
var getIncidentCount = Class.create();
getIncidentCount.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCount: function() {
var count = 0;
var assign = this.getParameter('sysparm_value'); // Corrected typo in getParameter
var user = new GlideAggregate('incident');
user.addQuery('assigned_to', assign);
user.addAggregate('COUNT', 'assigned_to');
user.groupBy('assigned_to');
user.query();
while (user.next()) {
count = user.getAggregate('COUNT', 'assigned_to');
gs.debug("Incident count is " + count);
}
return count;
},
type: 'getIncidentCount'
});
Also ensure the response handling in your GlideAjax is correct and matches the expected structure from the Script Include.
If you found my answer helpful or correct in any way, please don't forget to mark it to help future readers! 👍
--
Kind regards,
Marcos Kassak
Solution Consultant 🎯
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2023 09:55 PM
HI @Rose17 ,
I trust you are doing great.
Based on your description, here's the revised Script Include:
var getIncidentCount = Class.create();
getIncidentCount.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCount: function() {
var assign = this.getParameter('sysparm_value');
var agg = new GlideAggregate('incident');
agg.addQuery('assigned_to', assign);
agg.addAggregate('COUNT');
agg.query();
var count = 0;
if (agg.next()) {
count = agg.getAggregate('COUNT');
}
gs.log("Incident count for user " + assign + " is " + count);
return count;
},
type: 'getIncidentCount'
});
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi