Using comments and the console to debug scripts

  • Release version: Australia
  • Updated March 12, 2026
  • 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 Using comments and the console to debug scripts

    ServiceNow CPQ provides scripting capabilities in areas such as advanced conditions for rules, advanced actions for rules, and enrichments. The scripting language is JavaScript-like but does not include all JavaScript features. Effective debugging and testing of these scripts are essential before deployment in blueprints.

    Show full answer Show less

    Key Features

    • Console.log for Debugging: The console, accessed by clicking "Run Debugger," displays script output and helps verify script behavior by logging text and variables. This feature allows admins to observe the effect of their code and inputs live, such as viewing updates to BOM enrichment scripts.
    • Comments to Improve Code Maintenance: Comments are ignored by the script and are used to document code logic, save code snippets for later use, or temporarily disable code blocks without deletion.
    • Single-line Comments: Created with two slashes (//), these comments ignore everything after the slashes on the same line, allowing partial line commenting without affecting preceding code.
    • Multiline Comments: Created with / before and / after the comment block, enabling comments spanning multiple lines. These are useful for documenting larger sections or temporarily disabling multiple lines of code but require caution to avoid commenting out critical syntax like brackets or return statements.
    • Using Comments to Store Inputs: When working with complex rules that receive multiple inputs, admins can paste the inputs as multiline comments in the debugger. This practice saves time by preserving input data for quick reference or reuse during future script modifications.

    Key Outcomes

    • Admins can efficiently test and troubleshoot CPQ scripts by leveraging the console to monitor outputs and variable states.
    • Well-commented scripts improve code readability, maintainability, and facilitate collaboration or future updates.
    • Using comments strategically helps manage code versions and input data, reducing errors and accelerating development cycles in CPQ scripting.

    Learn how comments and the console can help you debug your scripts.

    ServiceNow CPQ has several areas where the admin can use scripts to define behavior. These include advanced conditions for rules, advanced actions for rules, and enrichments.

    Advanced conditions for rules

    Advanced conditions for Rules

    Advanced actions for rules

    Advanced conditions for Rules

    Enrichments

    Enrichments

    This article highlights a few key features to help you test and prepare your code before you deploy it in a blueprint.

    Note:
    The scripting language in ServiceNow CPQ is JavaScript-like, meaning it follows JavaScript-style syntax but lacks the full capabilities of JavaScript.

    Console.log

    When the admin starts to write a script, the ServiceNow CPQ Admin looks like this:

    Console.log

    Clicking Run Debugger in the lower panel raises the debugger and the Debugger Output section. This section is also called the console.

    This box shows the output of the script based on the script and the inputs added to the debugger (if applicable). For example, the BOM enrichment script shows the updated BOM based on the enrichment and inputs put in the debugger.

    Lines of code can be logged to the console. So, you can send text to the console, as in the following:

    Console.log

    You can also log variables, which is helpful to make sure your script is working correctly. You can add text to the log to help the lines of code stand out:

    Console.log

    Comments

    Comments are lines of code that the script ignores. Comments have a few uses. First, it is very helpful to future coders (and to you, when you revisit the code much later) if you have commented on how and why you coded lines of the script as you did. Commenting can also be used to save code to use again. And if you do not use a block of code but may want to use it later, you can comment it so it does not affect your current work.

    You can write comments on a single line or across multiple lines.

    To add single-line comments, use two slashes. Anything written after the slashes on the same line is ignored by the script.

    // This comment is ignored by the script

    However, any code before the slashes is still executed. For example, in the image below, the variable be4comment remains 12345, as the script ignores the comment "67890" following the slashes.

    Comments

    To create a multiline comment, add a slash and an asterisk before the comment. Add an asterisk and a slash after the comment.

    /*
    Your comment goes here.
    It can span multiple lines.
    */

    When you add a multiline comment, be careful not to comment out important elements such as closing brackets, parentheses, or return statements.

    Comments

    When you frequently revisit or modify a rule that takes inputs from many other fields, it can be helpful to paste the input into the debugger section as a multiline comment. This way, when you return to work on the rule later, you won't need to rewrite the inputs.

    /* inputs
    {"Field1": "testValue1",
        "Field2Quantity": 2,
          "Field3": "testValue3"
        },
    */