Unhandled Exception in GlideAjax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2025 09:08 AM
Need some help debugging my Client Script/ Script Include. The Client Script is supposed to call a Script Include to display JSON output from a REST message, in a form select box (drop-down) but it is throwing an Unhandled Exception in GlideAjax in the browser console.
CS:
function onLoad() {
// Get the control for the 'course_information' field using its field name
var courseSelect = g_form.getControl('course_information'); // Internal field name
// Ensure the field exists
if (courseSelect) {
// Create GlideAjax instance to call the Script Include
var ga = new GlideAjax('CourseInformation'); // Name of the Script Include
ga.addParam('method', 'getCourses'); // The method inside your Script Include that returns courses
// Fetch course data via GlideAjax and handle it asynchronously
ga.getXMLAnswer(function(response) {
var courseData = JSON.parse(response); // Parse the response to handle course data
// Clear any existing options in the dropdown
courseSelect.innerHTML = '';
// Add a default option to the dropdown
var defaultOption = document.createElement('option');
defaultOption.value = '';
defaultOption.text = '-- Select a Course --';
courseSelect.appendChild(defaultOption);
// Populate dropdown with course data
for (var i = 0; i < courseData.length; i++) {
var course = courseData[i];
var option = document.createElement('option');
option.value = course.crn; // Set CRN as the value
option.text = course.subject_code + " " + course.course_number; // Display subject_code + course_number
courseSelect.appendChild(option);
}
});
} else {
console.error('Field "course_information" is not found or rendered on the form.');
}
}
SI:
var CourseInformation = Class.create();
CourseInformation.prototype = {
initialize: function() {},
// Method to fetch course data from the LARF Banner Courses REST message
getCourses: function() {
var courseData = [];
// Create an instance of the RESTMessageV2 object
var restMessage = new sn_ws.RESTMessageV2();
restMessage.setRestMessageName('LARF Banner Courses'); // Your REST message name
var response = restMessage.execute();
var responseBody = response.getBody();
var responseData = JSON.parse(responseBody); // Assuming JSON response format
// Process and format the response data
for (var i = 0; i < responseData.length; i++) {
var course = responseData[i];
courseData.push({
crn: course.crn,
term_code: course.term_code,
part_of_term: course.part_of_term,
subject_code: course.subject_code,
course_number: course.course_number,
sequence: course.sequence,
faculty_cnumber: course.faculty_cnumber
});
}
// Return the formatted course data
return JSON.stringify(courseData);
},
type: 'CourseInformation'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2025 09:34 AM
Can you check if the script include is client callable?
if yes, the SI first two lines should be like below
Please mark it helpful
Regards
Priyatam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2025 10:42 AM - edited 03-06-2025 10:43 AM
Hi @appstorm
Kindly update below line of code in your client script and check.
ga.addParam('sysparm_name, 'getCourses'); // The method inside your Script Include that returns courses
Note: The first call to addParam should be with the parameter sysparm_name and the name of the server-side method you want to call.
Mark this helpful/ Accept the solution if it helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2025 10:57 AM
Thank you for your reply! I have made the change. However, the result remains the same.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2025 11:14 AM
Also getting this response in the console: "1 Uncaught (in promise) Error: A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received"