Lesson 3
3. Debugging
Debugging in ServiceNow is the process of identifying and fixing errors or unexpected behavior in applications, scripts, workflows, ACLs, or integrations. It helps ensure that processes run correctly and securely.
-
Enabling Session Debug:
Navigate to System Diagnostics > Session Debug and choose the desired debugging options (e.g., Business Rules, SQL, all).
-
Disabling Session Debug:
Under System Diagnostics > Session Debug, select Disable All.
-
Benefits:
Debugging, especially Session Debugging and ACL Debugging, provides several advantages for administrators and developers in ServiceNow.
-
Access Control Debugging:
Access Control Debugging in ServiceNow is the process of analyzing and troubleshooting ACL (Access Control List) rules to determine why a user can or cannot access certain records or fields.
It helps ensure data security and proper access permissions.
-
Accessing the Script Debugger:
You can access the Script Debugger from the application navigator, Studio, or the syntax editor.
-
Debugging Synchronous Scripts:
The Script Debugger is designed for debugging synchronous scripts like business rules, script includes, script actions, and UI actions.
-
How it Works:
Set breakpoints in your script. When the script executes, it will pause at each breakpoint, allowing you to inspect variable values and the call stack.
-
Key Features:
Breakpoints, call stack, line number, variables, and transaction details are displayed.
- Accessing Flow Debugger: Click the debug button in the top navigation bar while editing a flow.
- Debugging Flows: The execution view opens in debug mode, allowing you to set breakpoints at any flow step.
- Navigation: Use the top navigation buttons (resume, step over, step into, step out, skip all breakpoints) to navigate through the flow.
- Benefits: Pinpoints errors in complex flows, including nested subflows and loops.
-
JavaScript Log and Field Watcher:Enable these features under Settings > Developer in the banner frame. This opens the log viewer at the bottom of the window.
-
jslog() Statements:Use
jslog()statements within client scripts and UI policy scripts to output debugging information to the log viewer. These are preferred overalert()statements. -
Browser Console:
Check the browser’s console log (e.g., in Firefox or Chrome) for additional error messages not displayed elsewhere.
-
Strategic Logging:
Insert log statements at key points in your scripts to capture variable values, execution flow, and error messages.
-
Precision Breakpoints:
Use breakpoints strategically within complex logic or loops to isolate specific areas of code for analysis.
-
Variable Inspection:
Analyze variable values at different points in the script to identify inconsistencies or unexpected data.
-
System Logs:
Use the system logs to analyze errors, warnings, and other events that might be relevant to your debugging efforts.
-
GlideRecord Debugging:
Use GlideRecord methods to debug database interactions and ensure data consistency.
