Is there a way to preserve client side errors?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-25-2024 10:48 PM
If an error occurs on the client side, such as in a client script or UI page, where are the errors recorded?
I think there are logs that are recorded in the browser, but are there any that are recorded in a table?
I recently found something called a client transaction log, so I wondered if I could find out client error information as well.
I considered using "GlideAjax" as a way to save it somewhere, but I would like to know if there is a table that records it OOTB.
Or I would also like to know if there is a way to save it as a browser function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-26-2024 02:21 AM
server side errors etc are logged in system logs table
But client side errors only are seen in browser console
what's your business requirement here?
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
‎12-26-2024 04:59 AM
HI @bonsai ,
lient-side errors in ServiceNow, such as those from client scripts or UI pages, are typically logged in the browser's console and not stored in any table in ServiceNow out of the box (OOTB). While Client Transaction Logs (System Logs > Client Transaction Logs) provide performance data related to client-side actions, they do not record specific errors or exceptions. To capture such errors for later analysis, you can implement a custom solution using GlideAjax to log errors into a custom table. Below is a complete example of how this can be achieved.
You can create a client script that wraps your code in a try-catch block. When an error occurs, the script uses GlideAjax to send the error details to a Script Include. The Script Include then stores the error in a custom table.
try {
// Example of code that may cause an error
someUndefinedFunction(); // Intentional error for testing
} catch (error) {
// Log error details to the server using GlideAjax
var ga = new GlideAjax('ErrorLogger');
ga.addParam('sysparm_name', 'logError');
ga.addParam('sysparm_error', error.message); // Error message
ga.addParam('sysparm_stack', error.stack); // Stack trace for debugging
ga.getXMLAnswer(function(response) {
console.log('Error logged to the server: ', response.responseText);
});
}
var ErrorLogger = Class.create();
ErrorLogger.prototype = {
initialize: function() {},
logError: function() {
// Retrieve parameters from the GlideAjax call
var errorMessage = this.getParameter('sysparm_error');
var stackTrace = this.getParameter('sysparm_stack');
// Insert error details into a custom table
var gr = new GlideRecord('u_client_error_log'); // Custom table for logging errors
gr.initialize();
gr.error_message = errorMessage; // Map error message
gr.stack_trace = stackTrace; // Map stack trace
gr.reported_by = gs.getUserName(); // Add user details for context
gr.reported_at = new GlideDateTime(); // Add timestamp
gr.insert();
// Return success message
return 'Error logged successfully.';
},
type: 'ErrorLogger'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-26-2024 06:07 AM
Hello @bonsai ,
Only server side errors are logged in the servicenow in the 'Script Log Statements' if you want to capture the client side errors then you must implement the custom solution. Remember browser errors are independent of what happens in the blackened i.e. server. You can create a table and through GlideAjax send the captured errors to a script include and insert/log them in your custom table. What @Community Alums has suggested seems a proper solution. Let me know if you need help here.
Please mark the response as helpful if it assisted you in any way.
Thanks,
Mahesh.