Extraits de code de débogage dans les scripts

Cette page d'aide concerne Studio. Ces informations sont également disponibles pour Desktop Studio.

Vous pouvez déboguer les snippets à partir de la fenêtre de l'Éditeur de snippets de Snippet. Le débogueur vous permet de voir les variables dans le code snippet. Cela peut vous aider à résoudre des problèmes dans votre code. Cinq options sont disponibles pour déboguer les snippets :

En outre, si votre code contient des objets dynamiques ou des tableaux, vous pouvez voir leur contenu et la façon dont il change.

Utilisation de l'outil de débogueur

  1. Dans Studio, ouvrez un script contenant une action Snippet.
  2. Cliquez sur Ouvrir l'Éditeur A rectangle with a horizontal line near the top. sur l'action 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 Petits messages contextuels temporaires affichés au bas de l'écran indiquant des éléments tels que des erreurs et des réussites. 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.

Débogage avec un point d'arrêt

Vous pouvez définir un point d'arrêt si vous souhaitez que le débogage s'arrête à une ligne spécifique du code de du snippet. Vous pouvez définir plusieurs points d’arrêt et demander au débogueur de passer d’un point d’arrêt à l’autre. Cela vous permet de voir les variables et les valeurs à des points spécifiques de l'extrait sans le parcourir ligne par ligne.

Vous pouvez définir des points d'arrêt avant de démarrer le débogueur ou pendant son exécution. Le débogage s'arrête lorsque la ligne avec le point d'arrêt est sur le point d'être exécutée. Pendant la pause, vous pouvez voir la valeur actuelle de toutes les variables de l'extrait dans la section Variables de la fenêtre Exécuter et déboguer.

  1. Dans Studio, ouvrez un script contenant une action Snippet.
  2. Cliquez sur Ouvrir l'Éditeur A rectangle with a horizontal line near the top. sur l'action 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 Petits messages contextuels temporaires affichés au bas de l'écran indiquant des éléments tels que des erreurs et des réussites. 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.

Défilement dans le code de snippet

Vous pouvez utiliser l'outil de débogage pour faire défiler le code de snippet par ligne. Cela vous permet de voir comment les variables et leurs valeurs changent au fur et à mesure de l'exécution de chaque ligne.

  1. Dans Studio, ouvrez un script contenant une action Snippet.
  2. Cliquez sur Ouvrir l'Éditeur A rectangle with a horizontal line near the top. sur l'action 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 Petits messages contextuels temporaires affichés au bas de l'écran indiquant des éléments tels que des erreurs et des réussites. 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.

Déboguer à l'aide du mot-clé TRACE

Le mot-clé TRACE vous permet de déboguer à l'aide de la journalisation. Ce mot-clé ne fonctionne que lors de l'utilisation de l'outil de débogage dans la fenêtre de l'éditeur Snippet . Lorsque vous l'incluez dans votre extrait de code et exécutez le débogueur, le texte est affiché dans la section Trace de la fenêtre Exécuter et déboguer dans la fenêtre de l'éditeur Snippet .

Le mot-clé TRACE est ignoré en dehors de la fenêtre de l'éditeur Snippet. Il fonctionne uniquement avec l'outil de débogage.

La syntaxe est la suivante : TRACE "<expression>"

Le texte entre guillemets est envoyé vers la section Trace de la fenêtre Exécuter et déboguer dans la fenêtre de l'éditeur Snippet.

Vous pouvez utiliser la substitution de variable entre les guillemets doubles pour imprimer la valeur des variables. Par exemple :

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

La sortie de cet exemple dans la section Trace de la fenêtre Exécuter et déboguer est :

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

Utiliser la variable système de test

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 personne qui interagit avec un agent, un SRVI ou un robot dans votre centre d’appels., 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. Dans NiCE CXone, cliquez sur le sélecteur d'application et sélectionnez Omnicanal Routing > Studio Trois flèches jointes à la base. L'une pointe tout droit vers le haut, une autre vers le haut et à droite, et la dernière vers le haut et à gauche. .
  2. Dans la page Scripts, localisez et double-cliquez pour ouvrir le script avec lequel vous souhaitez travailler avec . Le script s’ouvre dans un nouvel onglet.
  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.