Debug Snippets

Deze pagina is bedoeld voor Desktop Studio. Momenteel ondersteunt CXone Studio de op deze pagina beschreven opties niet.

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:

  • Check the syntax in the snippet. You can do this at any time while coding a snippet. It doesn't use the debugger tool.
  • Debug the whole snippet to see variables and their values after the whole snippet has been executed.
  • Set a breakpoint to stop debugging at a certain line in the code.
  • Step through each line in the snippet code and see how the variable and their values change line by line.
  • Use TRACE statements to output data to the Trace pane in the Snippet editor window.

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

Check Snippet Syntax

You can have Studio check the syntax in a snippet.

  1. Open een script in Studio die een Snippet-actie bevat.
  2. Dubbelklik op de Snippet-actie.
  3. Add Snippet code on the Text View tab, if it doesn't already contain some.
  4. Click the Check Syntax icon An icon with three green circles in a cluster and a play button triangle next to them. at the bottom of the Snippet editor window.

    If no syntax errors are found, the status field next to the Check Syntax icon displays the message Okay.

    If syntax errors are found, an error message pops up describing the error. The description includes the line number where the error is located. Additionally the status field next to the Check Syntax icon displays the message Error at line [#].

  5. Correct any syntax issues that were found.
  6. You can select one or more lines in the snippet code and click the Comment out selected lines icon An icon with open and closed angle brackets next to each other with a blue forward slash between them.. This is helpful is you want to skip an error and check for any remaining errors.
  7. You can select one or more commented-out lines in the snippet code and click the Uncomment the selected lines icon An icon with open and closed angle brackets next to each other with a forward slash between them. A large red forward slash crosses the other characters..

Use the Debugger Tool

  1. Open een script in Studio die een Snippet-actie bevat.
  2. Dubbelklik op de Snippet-actie.
  3. Add Snippet code on the Text View tab, if it doesn't already contain some.
  4. On the right side of the Snippet editor window, click the Debugger tab.
  5. Click the down-arrow button on the right side of the Debug icon An icon of a window with a green right-facing triangle. On the right side of the icon is a down-facing black triangle that opens a drop-down menu. and select StartAn icon of a green play button triangle..
  6. If there are any syntax errors in the code, the Snippet editor window expands. All errors in the code appear in a pane at the bottom of the window. If there are no errors, skip to the next step.

    1. Correct the errors.
    2. When the errors have been corrected, click the Close or Clear Trace Output icons An X. to close the error pane.
    3. Start the debugger again.
  7. View the contents of the Variables as Text tab. The tab shows the variables and their values when all of the code has been executed if you didn't set a breakpoint.
  8. You can select one or more lines in the snippet code and click the Comment out selected lines icon An icon with open and closed angle brackets next to each other with a blue forward slash between them.. This is helpful if you want to remove some code to see how the outcome of the debugging changes.
  9. You can select one or more lines of commented-out code and click the Uncomment the selected lines icon An icon with open and closed angle brackets next to each other with a forward slash between them. A large red forward slash crosses the other characters. to add those lines back into the snippet.

Debug with a Breakpoint

You can set a breakpoint if you want debugging to stop at a specific line in the snippet code. This allows you to see the variables and values partway through the snippet without stepping through it line by line.

  1. Open een script in Studio die een Snippet-actie bevat.
  2. Dubbelklik op de Snippet-actie.
  3. Add Snippet code on the Text View tab, if it doesn't already contain some.
  4. Click in the column to the left of the line numbers in the Snippet editor window. A red circle appears at that line number.

  5. On the right side of the Snippet editor window, click the Debugger tab.
  6. Click the down-arrow button on the right side of the Debug icon An icon of a window with a green right-facing triangle. On the right side of the icon is a down-facing black triangle that opens a drop-down menu. and select StartAn icon of a green play button triangle..
  7. If there are any syntax errors in the code, the Snippet editor window expands. All errors in the code appear in a pane at the bottom of the window. If there are no errors, skip to the next step.

    1. Correct the errors.
    2. When the errors have been corrected, click the Close or Clear Trace Output icons An X. to close the error pane.
    3. Start the debugger again.
  8. View the contents of the Variables as Text tab. The tab 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.
  9. If you're done with the breakpoint, click the red circle again to clear it.
  10. Set another breakpoint, if you need one.
  11. To continue debugging from the breakpoint, click the Resume icon An icon of a green play triangle..
  12. To stop debugging, click the Stop Debugging A black square. icon.

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. Open een script in Studio die een Snippet-actie bevat.
  2. Dubbelklik op de Snippet-actie.
  3. Add Snippet code on the Text View tab, if it doesn't already contain some.
  4. On the right side of the Snippet editor window, click the Debugger tab.
  5. Click the down-arrow button on the right side of the Debug icon An icon of a window with a green right-facing triangle. On the right side of the icon is a down-facing black triangle that opens a drop-down menu. and select StartAn icon of a green play button triangle..
  6. If there are any syntax errors in the code, the Snippet editor window expands. All errors in the code appear in a pane at the bottom of the window. If there are no errors, skip to the next step.

    1. Correct the errors.
    2. When the errors have been corrected, click the Close or Clear Trace Output icons An X. to close the error pane.
    3. Start the debugger again.
  7. View the contents of the Variables as Text tab. It displays the variables in the code and their values when the snippet code starts.
  8. Click the Step icon An icon to move to the next line in the snippet.
  9. Repeat steps the preceding two steps for each line in the snippet.
  10. If you want to skip the remaining lines of code, click the Resume icon An icon of a green play button triangle.. The Variables as Text tab displays the variables and their values when all of the snippet code has executed.
  11. To stop debugging, click the Stop Debugging A black square. icon, then repeat this process starting from step 3.

View Contents of Dynamic Objects and Arrays

You can view the contents of dynamic objects in the Snippet editor window when you run the debugger. This allows you to verify that the object holds the data it's supposed to at each step in your code.

  1. In Studio, double-click on a Snippet action.
  2. Add snippet code, if necessary.
  3. On the Debugger tab, click the Variables as Tree tab.
  4. On the Debugger tab, click the down arrow next to the Start Debugging icon An image of a triangular green play buttonand select Step Into A series of horizontal lines with an arrow pointing from one line to the one beneath it.. If you don't want to step through the code line by line, click the Start Debugging icon.
  5. Click the Step A series of horizontal lines with an arrow pointing from one line to the one beneath it. icon and observe the contents on the Variables as Tree tab. Each time you click Step, this field updates with the variables and objects in the script after the previous line of code. Skip this step if you clicked Start Debugging.
  6. When you have stepped through all lines of code or if you clicked Start Debugging, the Variables as Tree tab displays all variables, objects, and their contents at the end of the snippet.
  7. You can click the + icon next to any string arrays or dynamic objects in the code to expand them. If the content is another array or object, you can continue to expand the tree to see what each entity contains.

Debug using TRACE

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 pane that appears at the bottom of the Snippet editor window.

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

The syntax is: TRACE "<text>"

Text within the double quotes is output to the Snippet editor window. It appears in the Trace pane at the bottom of the 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 is:

I = 1

I = 2

I = 3

I = 4

I = 5