Debug Snippets in Studio

This help page is for Studio. This information is also available for Desktop Studio.

You can debug snippets from the Snippet editor window. The debugger allows you to see the variables in the snippet code. This can help you solve problems in your code. There are five options for debugging snippets: 

Additionally, if your code contains dynamic objects or arrays, you can see their contents and how it changes.

Use the Debugger Tool

  1. In Studio, open a script containing a Snippet action.
  2. Click Open Editor A rectangle with a horizontal line near the top. on the Snippet action.
  3. Add Snippet code, if it doesn't already contain some.
  4. On the left side of the Snippet editor window, click the bug Icon of a bug.. The Run & Debug panel slides out from the left side of the window.
  5. Click the triangle Icon of a triangle pointing to the right. to start debugging.
  6. View the contents of the Variables section of the Run & Debug panel. This section shows the variables and their values when the debugger has executed all of the snippet code. Dynamic data objects show the value {Dynamic}. Click to expand them and view the values of their members.
  7. Check for errors in the _err variable at any point in the debugging process. Some errors pop up as toastClosed Toast messages are small, temporary pop-up messages on the bottom of the screen indicating things like errors and successes. They are built-in to CXone Mpower functionality and can appear on any screen. messages in the Snippet editor window.

  8. To make changes to your snippet: 
    1. Stop the debugger, if it's not already stopped. While the debugger is running, the snippet is in read-only mode.
    2. Make your changes.
    3. Click Apply in the Snippet editor window. The editor window automatically closes. This sends the changes to the server, where the debugging service runs.
    4. Reopen the Snippet editor window and run the debugger again.

Debug with a Breakpoint

You can set a breakpoint if you want debugging to stop at a specific line in the snippet code. You can set more than one breakpoint and have the debugger skip from breakpoint to breakpoint. This allows you to see the variables and values at specific points in the snippet without stepping through it line by line.

You can set breakpoints before you start the debugger or while it's running. The debugging pauses when the line with the breakpoint is about to be executed. While paused, you can see the current value of all variables in the snippet in the Variables section of the Run & Debug window.

  1. In Studio, open a script containing a Snippet action.
  2. Click Open Editor A rectangle with a horizontal line near the top. on the Snippet action.
  3. Add Snippet code, if it doesn't already contain some.
  4. On the left side of the Snippet editor window, click the bug Icon of a bug.. The Run & Debug panel slides out from the left side of the window.
  5. Add a breakpoint by clicking in the column to the left of any line in the Snippet editor window. A red circle appears next to the line number. You can add more than one breakpoint to the snippet. You can also add breakpoints while the debugger is running.

  6. Click the triangle Icon of a triangle pointing to the right. to start debugging.
  7. View the contents of the Variables section of the Run & Debug panel. This section shows the variables and their values at the breakpoint, if you set one. The line where the debugging paused for the breakpoint is highlighted in the Snippet editor window. Dynamic data objects show the value {Dynamic}. Click to expand them and view the values of their members.
  8. If you're done with a breakpoint, click the red circle again to clear it.
  9. To continue debugging from the breakpoint, click resume Icon of a vertical line with a triangle next to it.. If you have set more than one breakpoint, the debugger pauses just before the next one.
  10. To step through the code line by line from the current breakpoint, click the down-arrow Icon of an arrow pointing down.. You can resume Icon of a vertical line with a triangle next to it. at any point to finish debugging or to jump to the next breakpoint.
  11. Check for errors in the _err variable at any point in the debugging process. Some errors pop up as toastClosed Toast messages are small, temporary pop-up messages on the bottom of the screen indicating things like errors and successes. They are built-in to CXone Mpower functionality and can appear on any screen. messages in the Snippet editor window.

  12. To stop debugging, click the square Icon of an empty square..
  13. To make changes to your snippet: 
    1. Stop the debugger, if it's not already stopped. While the debugger is running, the snippet is in read-only mode.
    2. Make your changes.
    3. Click Apply in the Snippet editor window. The editor window automatically closes. This sends the changes to the server, where the debugging service runs.
    4. Reopen the Snippet editor window and run the debugger again.

Step Through Snippet Code

You can use the debugger tool to step through the snippet code line by line. This allows you to see how the variables and their values change as each line is executed.

  1. In Studio, open a script containing a Snippet action.
  2. Click Open Editor A rectangle with a horizontal line near the top. on the Snippet action.
  3. Add Snippet code, if it doesn't already contain some.
  4. On the left side of the Snippet editor window, click the bug Icon of a bug.. The Run & Debug panel slides out from the left side of the window.
  5. Click in the column to the left of any line in the Snippet editor window. A red circle appears next to the line. This is a breakpoint, which marks the place from which you can start stepping through the code.

  6. Click the triangle Icon of a triangle pointing to the right. to start debugging. If the breakpoint is on the first line, no code is executed yet.
  7. View the contents of the Variables section of the Run & Debug panel. This section displays the variables in the code and their values before the snippet code starts. Dynamic data objects show the value {Dynamic}. Click to expand them and view the values of their members.
  8. Click the down-arrow Icon of an arrow pointing down. to move to the next line in the snippet. The Variables section updates to show the variables and their values after executing the first line of snippet code.
  9. Repeat the preceding two steps for each line in the snippet. The Variables section continues to update after each line.
  10. If you want to skip the remaining lines of code, click resume Icon of a vertical line with a triangle next to it.. The Variables section displays the variables and their values when all of the snippet code has executed.
  11. Check for errors in the _err variable at any point in the debugging process. Some errors pop up as toastClosed Toast messages are small, temporary pop-up messages on the bottom of the screen indicating things like errors and successes. They are built-in to CXone Mpower functionality and can appear on any screen. messages in the Snippet editor window.

  12. To stop debugging, click the square Icon of an empty square., then repeat the debugging process if needed.
  13. To make changes to your snippet: 
    1. Stop the debugger, if it's not already stopped. While the debugger is running, the snippet is in read-only mode.
    2. Make your changes.
    3. Click Apply in the Snippet editor window. The editor window automatically closes. This sends the changes to the server, where the debugging service runs.
    4. Reopen the Snippet editor window and run the debugger again.

Debug using the TRACE Keyword

The TRACE keyword allows you to debug using logging. This keyword only works when using the debugger tool in the Snippet editor window. When you include it in your snippet code and run the debugger, text is output to the Trace section of the Run & Debug window in the Snippet editor window.

The TRACE keyword is ignored outside of the Snippet editor window. It only works with the debugger tool.

The syntax is: TRACE "<expression>"

Text within the double quotes is output to Trace section of the Run & Debug window in the Snippet editor window.

You can use variable substitution between the double quotes to print the value of variables. For example:

FOR i=1 TO 5
{
   TRACE "I = {i}"
}

The output from this example in the Trace section of the Run & Debug window is: 

I = 1
I = 2
I = 3
I = 4
I = 5