Example Use of the Script Debugger Buttons and Tabs

The following example shows how to debug a script using the execute, step over, and step into buttons. This example also shows how to use the Execution Log, Local Variables, and Watches tabs.

Note:

The code in this example assumes you have at least two customers with an entityId that includes 'Adam'.

  1. Go to Customization > Scripting > Script Debugger.

  2. Enter the following code into the debugger window:

                  /** * @NApiVersion 2.x */ require (['N/search'], function (search) { var mySearch = search.create({ type: search.Type.CUSTOMER, columns: ['entityid', 'firstname', 'lastname', 'salesrep'], filters: ['entityid', 'contains', 'Adam'] }); var myResultSet = mySearch.run(); var resultRange = myResultSet.getRange({ start: 0, end: 50 }); for (var i = 0; i < resultRange.length; i++) { log.debug(resultRange[i]); }
    }); 
    
                
  3. In the API Version dropdown list, select 2.0.

  4. Click Debug Script.

  5. Wait until the script is shown in the window with the first line highlighted. At this point, the script has not yet started to run.

    The Script Debugger execution stopped on the script require statement.
  6. Set a breakpoint at the var myResultSet = mySearch.run() line by clicking between the line number (11) and the code line. Notice that when you add or remove a breakpoint, “Running Script” is briefly displayed:

    Indication of a running script.

    However, the script is not running. But, the breakpoint is being inserted into the proper location.

  7. Set another breakpoint at the for line (line 18). The two breakpoints are shown like this:

    Script Debugger with two break points set.
  8. Click the Continue button Example Use of the Script Debugger Buttons and Tabs to execute the script to the first breakpoint.

  9. When the breakpoint is reached, the debugger pauses execution and highlights the line:

    Script Debugger stopped on a break point highlights the line.
  10. Click the Step Over button to execute the mySearch.run() line to get your search results:

    Script Debugger with the Step Over button highlighted.

    The debugger runs the search and pause at the next line of code:

    Script Debugger manually paused between two break points.
  11. While the debugger is paused, click the Local Variables subtab to view the value of the myResultSet variable:

    Script Debugger Local Variables tab with a variable fully expanded.
  12. Click the Continue button to continue executing the script to the next breakpoint (line 18):

    Script Debugger stopped on a break point.
  13. When the debugger pauses on line 18, click the Step Into button:

    Script Debugger with Step Into button highlighted.

    The debugger will execute the for line and pause at the first line in the for loop block of code, which is the log.debug statement:

    Script Debugger stopped on line following a break point.
  14. While the debugger is paused, add a watch for the resultRange variable to watch the variable value update as the for loop. Enter resultRange into the Add Watch box on the Watches subtab and press the Enter key to see the value.

    Script Debugger Watches tab with watch variables expanded.
  15. Click the Continue button. The debugger executes one iteration of the for loop and will again pause.

  16. On the Watches tab, expand the resultRange variable to view its current value

    Script Debugger Watches tab with watch variables expanded.
  17. Click the second breakpoint to remove it. You must remove the breakpoint so the debugger does not pause at every iteration of the for loop. You can remove any breakpoint at anytime while the debugger is paused.

  18. Click the Continue button to finish executing the script.

When the script completes execution, the Execution Log subtab shows all your log.debug statements:

Script Debugger Execution Log tab with two debug statements.

Related Topics

Script Debugger Interface
Script Debugger Buttons
Tips for Debugging SuiteScript 1.0 and SuiteScript 2.0 Scripts

General Notices