- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2025 07:50 AM
I am using a non-client callable Script Include and a script in workflow editor to post data, via REST API. However, I keep getting this error: [Late Add Script] Exception during REST call: "GlideRestMessage" is not defined.
Workflow Script
// Access the student_information and course_information reference fields from the current record
var studentInfo = current.variables.student_information; // Reference to the LARF Banner Student record
var courseInfo = current.variables.course_information; // Reference to the LARF Banner Courses record
// Initialize variables for student_id, crn, and term_code
var studentId, crn, termCode;
// --- Step 1: Retrieve Student ID using Script Include ---
if (studentInfo) {
var studentId = new LateAddHelper().getStudentId(studentInfo); // Call the Script Include to get student ID
if (studentId) {
gs.info("[Late Add Script] Successfully retrieved student ID: " + studentId);
} else {
gs.error("[Late Add Script] Could not retrieve student ID.");
}
} else {
gs.error("[Late Add Script] student_information is not set or invalid.");
}
// --- Step 2: Retrieve CRN and Term Code ---
if (courseInfo) {
var courseGR = new GlideRecord('sn_uni_req_larf_banner_courses');
if (courseGR.get(courseInfo)) {
crn = courseGR.u_crn;
termCode = courseGR.u_term_code;
gs.info("[Late Add Script] Retrieved CRN: " + crn + ", Term Code: " + termCode);
} else {
gs.error("[Late Add Script] Course record not found for course_information: " + courseInfo);
}
} else {
gs.error("[Late Add Script] course_information is not set or invalid.");
}
// --- Step 3: Invoke REST API using the "LARF Banner Student Late-Add" REST Message ---
if (studentId && crn && termCode) {
try {
gs.info("[Late Add Script] All required parameters are present. Preparing REST call...");
// Instantiate the GlideRestMessage object
var restMessage = new GlideRestMessage();
// Set the REST message by name ("LARF Banner Student Late-Add" as per your configuration)
restMessage.setRestMessageName('LARF Banner Student Late-Add');
// Set the HTTP method (configured in the REST message; in this case, "Default" -> POST)
restMessage.setHttpMethod('Default'); // Ensure the method is POST as per the configuration
// Set the parameters (these are the fields you need to pass to the API)
restMessage.setStringParameter('student_id', studentId);
restMessage.setStringParameter('crn', crn);
restMessage.setStringParameter('term_code', termCode);
restMessage.setStringParameter('stst_code', 'RE'); // Set status code as 'RE' for late-add
gs.info("[Late Add Script] Sending REST request with student_id: " + studentId + ", crn: " + crn + ", term_code: " + termCode);
// Execute the REST message and capture the response
var response = restMessage.execute();
// Parse the response
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info("[Late Add Script] REST Response Status: " + httpStatus);
gs.info("[Late Add Script] REST Response Body: " + responseBody);
// Handle the response status
if (httpStatus == 200 || httpStatus == 201) {
gs.info("[Late Add Script] Successfully sent data to Banner for student ID: " + studentId);
} else {
gs.error("[Late Add Script] Failed to send data to Banner. HTTP Status: " + httpStatus + ", Body: " + responseBody);
}
} catch (e) {
gs.error("[Late Add Script] Exception during REST call: " + e.message);
}
} else {
gs.error("[Late Add Script] Missing one or more required parameters (studentId, crn, termCode). Aborting REST call.");
}
Script Include
var LateAddHelper = Class.create();
LateAddHelper.prototype = {
initialize: function() {},
getStudentId: function(studentSysId) {
if (!studentSysId) {
gs.error("[Late Add Script] studentSysId is not provided.");
return null;
}
var studentGR = new GlideRecord('sn_uni_req_larf_banner_student');
if (studentGR.get(studentSysId)) {
var studentId = studentGR.u_employee_number;
gs.info("[Late Add Script] Retrieved Student ID: " + studentId);
return studentId;
} else {
gs.error("[Late Add Script] Student record not found for Sys ID: " + studentSysId);
return null;
}
},
type: 'LateAddHelper'
};
I have also tried using RESTMessageV2 with the same result.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2025 07:59 AM
GlideRestMessage is not a valid class
updated workflow script
// Access the student_information and course_information reference fields from the current record
var studentInfo = current.variables.student_information; // Reference to the LARF Banner Student record
var courseInfo = current.variables.course_information; // Reference to the LARF Banner Courses record
// Initialize variables for student_id, crn, and term_code
var studentId, crn, termCode;
// --- Step 1: Retrieve Student ID using Script Include ---
if (studentInfo) {
studentId = new LateAddHelper().getStudentId(studentInfo); // Call the Script Include to get student ID
if (studentId) {
gs.info("[Late Add Script] Successfully retrieved student ID: " + studentId);
} else {
gs.error("[Late Add Script] Could not retrieve student ID.");
}
} else {
gs.error("[Late Add Script] student_information is not set or invalid.");
}
// --- Step 2: Retrieve CRN and Term Code ---
if (courseInfo) {
var courseGR = new GlideRecord('sn_uni_req_larf_banner_courses');
if (courseGR.get(courseInfo)) {
crn = courseGR.u_crn;
termCode = courseGR.u_term_code;
gs.info("[Late Add Script] Retrieved CRN: " + crn + ", Term Code: " + termCode);
} else {
gs.error("[Late Add Script] Course record not found for course_information: " + courseInfo);
}
} else {
gs.error("[Late Add Script] course_information is not set or invalid.");
}
// --- Step 3: Invoke REST API using the "LARF Banner Student Late-Add" REST Message ---
if (studentId && crn && termCode) {
try {
gs.info("[Late Add Script] All required parameters are present. Preparing REST call...");
// Instantiate the RESTMessageV2 object
var restMessage = new sn_ws.RESTMessageV2('LARF Banner Student Late-Add', 'Default'); // Ensure the method is POST as per the configuration
// Set the parameters (these are the fields you need to pass to the API)
restMessage.setStringParameter('student_id', studentId);
restMessage.setStringParameter('crn', crn);
restMessage.setStringParameter('term_code', termCode);
restMessage.setStringParameter('stst_code', 'RE'); // Set status code as 'RE' for late-add
gs.info("[Late Add Script] Sending REST request with student_id: " + studentId + ", crn: " + crn + ", term_code: " + termCode);
// Execute the REST message and capture the response
var response = restMessage.execute();
// Parse the response
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info("[Late Add Script] REST Response Status: " + httpStatus);
gs.info("[Late Add Script] REST Response Body: " + responseBody);
// Handle the response status
if (httpStatus == 200 || httpStatus == 201) {
gs.info("[Late Add Script] Successfully sent data to Banner for student ID: " + studentId);
} else {
gs.error("[Late Add Script] Failed to send data to Banner. HTTP Status: " + httpStatus + ", Body: " + responseBody);
}
} catch (e) {
gs.error("[Late Add Script] Exception during REST call: " + e.message);
}
} else {
gs.error("[Late Add Script] Missing one or more required parameters (studentId, crn, termCode). Aborting REST call.");
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2025 07:59 AM
GlideRestMessage is not a valid class
updated workflow script
// Access the student_information and course_information reference fields from the current record
var studentInfo = current.variables.student_information; // Reference to the LARF Banner Student record
var courseInfo = current.variables.course_information; // Reference to the LARF Banner Courses record
// Initialize variables for student_id, crn, and term_code
var studentId, crn, termCode;
// --- Step 1: Retrieve Student ID using Script Include ---
if (studentInfo) {
studentId = new LateAddHelper().getStudentId(studentInfo); // Call the Script Include to get student ID
if (studentId) {
gs.info("[Late Add Script] Successfully retrieved student ID: " + studentId);
} else {
gs.error("[Late Add Script] Could not retrieve student ID.");
}
} else {
gs.error("[Late Add Script] student_information is not set or invalid.");
}
// --- Step 2: Retrieve CRN and Term Code ---
if (courseInfo) {
var courseGR = new GlideRecord('sn_uni_req_larf_banner_courses');
if (courseGR.get(courseInfo)) {
crn = courseGR.u_crn;
termCode = courseGR.u_term_code;
gs.info("[Late Add Script] Retrieved CRN: " + crn + ", Term Code: " + termCode);
} else {
gs.error("[Late Add Script] Course record not found for course_information: " + courseInfo);
}
} else {
gs.error("[Late Add Script] course_information is not set or invalid.");
}
// --- Step 3: Invoke REST API using the "LARF Banner Student Late-Add" REST Message ---
if (studentId && crn && termCode) {
try {
gs.info("[Late Add Script] All required parameters are present. Preparing REST call...");
// Instantiate the RESTMessageV2 object
var restMessage = new sn_ws.RESTMessageV2('LARF Banner Student Late-Add', 'Default'); // Ensure the method is POST as per the configuration
// Set the parameters (these are the fields you need to pass to the API)
restMessage.setStringParameter('student_id', studentId);
restMessage.setStringParameter('crn', crn);
restMessage.setStringParameter('term_code', termCode);
restMessage.setStringParameter('stst_code', 'RE'); // Set status code as 'RE' for late-add
gs.info("[Late Add Script] Sending REST request with student_id: " + studentId + ", crn: " + crn + ", term_code: " + termCode);
// Execute the REST message and capture the response
var response = restMessage.execute();
// Parse the response
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info("[Late Add Script] REST Response Status: " + httpStatus);
gs.info("[Late Add Script] REST Response Body: " + responseBody);
// Handle the response status
if (httpStatus == 200 || httpStatus == 201) {
gs.info("[Late Add Script] Successfully sent data to Banner for student ID: " + studentId);
} else {
gs.error("[Late Add Script] Failed to send data to Banner. HTTP Status: " + httpStatus + ", Body: " + responseBody);
}
} catch (e) {
gs.error("[Late Add Script] Exception during REST call: " + e.message);
}
} else {
gs.error("[Late Add Script] Missing one or more required parameters (studentId, crn, termCode). Aborting REST call.");
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2025 08:06 AM
Hello @appstorm ,
Correct syntax to glide Rest Message is as below :
var restMessage = new sn_ws.RESTMessageV2();
If this solution helped resolve your issue, please consider marking it as helpful or correct.
This will assist others in finding the solution faster and close the thread.