Fragmentos de depuración en Scripts

Esta página de ayuda es para Studio. Esta información también está disponible para Desktop Studio.

Puede depurar los snippets desde la ventana del editor Snippet. El depurador le permite ver las variables en el código de snippets. Esto puede ayudarlo a resolver problemas en su código. Hay cinco opciones para depurar snippets:

Además, si su código contiene matrices u objetos dinámicos, puede ver su contenido y como cambia.

Utilice la Herramienta de depuración

  1. En Studio, abra un script que contenga una acción Snippet.
  2. Haga clic en Abrir editor Un rectángulo con una línea horizontal cerca de la parte superior. en la acción Snippet.
  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. In this section: 

    • Dynamic data objects show the value {Dynamic}. Click to expand them and view the values of their members.
    • Hover the cursor over a value to see that value in a tooltip. This allows you to see large values.
    • Click a value and press CTRL+C to copy the value to your clipboard.
  7. Check for errors in the _err variable at any point in the debugging process. Some errors pop up as toastClosed mensajes emergentes pequeños y temporales en la parte inferior de la pantalla que indican cosas como errores y éxitos. messages in the Snippet editor window.

  8. To make changes to your snippet: 
    1. Stop the debugger, if it's running. 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.

Depurar con un punto de interrupción

Puede definir un punto de interrupción si desea que se detenga la depuración en una línea específica del código del snippet. Puede establecer más de un punto de interrupción y hacer que el depurador salte de un punto de interrupción a otro. Esto le permite ver las variables y los valores en puntos específicos del fragmento sin tener que recorrerlo línea por línea.

Puede establecer puntos de interrupción antes de iniciar el depurador o mientras se está ejecutando. La depuración se detiene cuando la línea con el punto de interrupción está a punto de ejecutarse. Mientras está en pausa, puede ver el valor actual de todas las variables en el fragmento en la sección Variables de la ventana Ejecutar y depurar.

  1. En Studio, abra un script que contenga una acción Snippet.
  2. Haga clic en Abrir editor Un rectángulo con una línea horizontal cerca de la parte superior. en la acción Snippet.
  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 dot 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 and an open arrow Icon of a yellow arrow appears in the breakpoint column. In this section: 

    • Dynamic data objects show the value {Dynamic}. Click to expand them and view the values of their members.
    • Hover the cursor over a value to see that value in a tooltip. This allows you to see large values.
    • Click a value and press CTRL+C to copy the value to your clipboard.
  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 mensajes emergentes pequeños y temporales en la parte inferior de la pantalla que indican cosas como errores y éxitos. 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 running. 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.

Paso a paso del Código de Snippets

Puede usar la herramienta de depuración para recorrer el fragmento de código línea por línea. Esto le permite ver cómo cambian las variables y sus valores a medida que se ejecuta cada línea.

  1. En Studio, abra un script que contenga una acción Snippet.
  2. Haga clic en Abrir editor Un rectángulo con una línea horizontal cerca de la parte superior. en la acción Snippet.
  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 dot 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. In this section: 

    • Dynamic data objects show the value {Dynamic}. Click to expand them and view the values of their members.
    • Hover the cursor over a value to see that value in a tooltip. This allows you to see large values.
    • Click a value and press CTRL+C to copy the value to your clipboard.
  8. Click the down-arrow Icon of an arrow pointing down. in the Run & Debug panel 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 mensajes emergentes pequeños y temporales en la parte inferior de la pantalla que indican cosas como errores y éxitos. 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 running. 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.

Depurar utilizando la palabra clave TRACE

La palabra clave TRACE le permite depurar mediante el registro. Esta palabra clave solo funciona cuando se usa la herramienta de depuración en la ventana del editorSnippet . Cuando lo incluye en su fragmento de código y ejecuta el depurador, el texto se envía a la sección Rastreo de la ventana Ejecutar y depurar en la ventana del editor Snippet .

La palabra clave TRACE se ignora fuera de la ventana del editor Snippet. Únicamente funciona con la herramienta de depuración.

La sintaxis es: TRACE "<expression>"

El texto entre comillas dobles se envía a la sección Seguimiento de la ventana Ejecutar y depurar en la ventana del editor Snippet.

Puede utilizar la sustitución de variables entre las comillas dobles para imprimir el valor de las variables. Por ejemplo:

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

El resultado de este ejemplo en la sección Seguimiento de la ventana Ejecutar y depurar es:

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

Utilice la variable del sistema de prueba

The test variable is a system variable reserved for use in debugging snippets. It allows you to set the value of variables that are used in the snippet and would already be populated by the script before it hits the SNIPPET action.

When you use test in a snippet, it must be used as part of an IF statement and set to 1. The code between the curly brackets only executes when you run the snippet debugger because the test variable only equals 1 when the debugger runs. When the script runs for a contactClosed La persona que interactúa con un agente, IVR o bot en su centro de contacto., test has the value of 0, so the code between the curly brackets in the IF statement is ignored.

For example: 

IF test = {
 ASSIGN myDate = "07/03/2026" //This date falls on a Friday}
ASSIGN myDow = myDate.asdatedow
SWITCH myDow
{
 CASE 0   { ASSIGN newToday = "Sunday"  }
 CASE 1   { ASSIGN newToday = "Monday"  }
 CASE 2   { ASSIGN newToday = "Tuesday" }
 CASE 3   { ASSIGN newToday = "Wednesday" }
 CASE 4   { ASSIGN newToday = "Thursday" }
 CASE 5   { ASSIGN newToday = "Friday"  }
 CASE 6   { ASSIGN newToday = "Saturday"   }
}

In this example, the ASSIGN statement within the IF statement sets the initial condition of the myDate variable. In a live script, this value would be set elsewhere in the script and the value set in the IF statement would be ignored. The reason you need it in debugging the snippet is that the full script isn't running to set that value.

  1. En NiCE CXone, haga clic en el selector de aplicaciones y seleccione Omnicanal Routing > Studio Tres flechas unidas por la base. Una apunta directamente hacia arriba, otra hacia arriba y a la derecha, y otra hacia arriba y a la izquierda. .
  2. En la página Scripts, ubique y haga doble clic para abrir el script con el que desea trabajar. Se abre el script en una nueva pestaña.
  3. Open a SNIPPET action or add a new one to the canvas.

  4. At the top of the Snippet editor window, add the following code:

    IF test = 1
    {
    	[code or variable assignments]
    }
  5. In place of [code or variable assignments], insert whatever code or ASSIGN statements you need to set the initial conditions required for the snippet to run, such as setting initial variable values that your snippet code requires. For example: 

    IF test = 1 {
     ASSIGN MyDate = "07/03/2026" //This date falls on a Friday
    }
  6. Add the snippet code that you want to test. For example:

    ASSIGN myDow = myDate.asdatedow
    SWITCH myDow
    {
     CASE 0   { ASSIGN newToday = "Sunday"  }
     CASE 1   { ASSIGN newToday = "Monday"  }
     CASE 2   { ASSIGN newToday = "Tuesday" }
     CASE 3   { ASSIGN newToday = "Wednesday" }
     CASE 4   { ASSIGN newToday = "Thursday" }
     CASE 5   { ASSIGN newToday = "Friday"  }
     CASE 6   { ASSIGN newToday = "Saturday"   }
    }
  7. To test the code, click the bug Icon of an insect. to open the debugger.

  8. Click Apply to save the snippet, then save your script.