Script Tracer and debugging scripts

  • Release version: Xanadu
  • Updated August 1, 2024
  • 2 minutes to read
  • Summarize
    Summarized using AI
    This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.

    Summary of Script Tracer and debugging scripts

    The Script Tracer is a powerful tool in ServiceNow that helps administrators efficiently debug scripts and business rules by filtering and narrowing down script changes during execution. It identifies specific lines in the Glide record that have changed, saving time and increasing productivity. To access the Script Tracer, search for it in the left navigation pane. Note that only users with the admin role can use this feature.

    Show full answer Show less

    Key Features

    • Execution Filtering: Once enabled and after executing a UI transaction, the Script Tracer scans all running scripts for changes.
    • Filter Options: You can filter traces by file type or by the specific table related to the script execution.
    • State Tab: Displays differences between old and new script states, with an option to view only changed values or all values.
    • Error Reporting: Errors encountered during execution are displayed at the top of the State tab with line numbers and messages.
    • Script Details: View lines of changed scripts, open scripts in the Debugger for detailed debugging, or open the script for editing within the platform.
    • Transaction Records: Lists all transaction records related to the trace for comprehensive analysis.
    • Trace Management: Ability to clear traces when finished and set limits on the maximum number of lines traced.

    Practical Usage and Configuration

    By default, the Script Tracer captures up to 1,000 lines of script changes. To avoid overwhelming results, it is recommended to clear the trace before starting a new one. You can adjust the maximum number of trace lines by configuring the system property glide.debug.trace.tracelinelimit.

    This tool helps quickly identify problematic script areas by focusing only on changes during execution, thereby streamlining your debugging process and improving script troubleshooting efficiency.

    The Script Tracer can help you filter your debugging search to quickly narrow down script problems. You can identify lines of scripts in the Glide record that have undergone change during execution. Finding those specific lines of scripts rather than doing a wide search helps save time and improves productivity.

    Overview

    Use the Script Tracer to narrow your search so you can debug scripts and business rules more efficiently. You can find the Script Tracer by searching in the left navigation pane.
    Note:
    To use the Script Tracer, your role must be admin.
    Script Tracer in the navigation pane Script Tracer tab
    Once you enable Script Tracer and execute a UI transaction, the Tracer searches through all the scripts being executed. The following filters are available:
    • File type: Search for a specific file type
    • Table: Look in the specific table for the script being executed

    The Script Tracer searches for changes in the script during execution and presents them in a list for you to examine. When you click Start Tracer, the Tracer begins searching for changes in the Glide record. You can click the Debug Script button at any time to see the script itself.Script difference output

    Use the tabs to see specific information from the Tracer.

    The State tab displays the differences between the old and new scripts.
    • By default, the Show only changed values check box is enabled, so you can avoid fields that have not changed.
    • To view all the fields (changed or not), you can clear that check box.
    Note:
    If the file is not reflected in the trace statement, it means the changes in the Glide record is not recognized by the system.

    If there are any errors, they display at the top of the State tab, with their line numbers and error message displayed in order of occurrence.Errors listed in the State tab.

    • Script: Displays the line of changed scripts that the Glide record has undergone during execution. You can view the entire line of script by clicking the Show Script button.
    • Transaction: Shows all transaction records of the trace
    • Debug Script: Opens the script in Debugger to debug the script
    • View File: Opens the script in the ServiceNow platform for editing
    • Clear trace: Clears the trace when you are finished.

    Limiting the tracer

    You may want to set a limit for your trace so that you don't generate too many returns. By default there will be up to 1,000 lines of script traced. Once this number is reached you must clear the trace and start tracing again. If you want to change the maximum number of lines for tracing you can configure your limit using the property glide.debug.trace.trace_line_limit.

    Since each trace you run is new, make sure you're finished reading the results of one trace before clearing it and beginning another one.

    To learn more, see Debugging scripts.