SNIPPET

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

Le permite agregar código personalizado a su script.

Making REST API calls from a SNIPPET action is strongly discouraged. Instead, use the REST API action or Integration Hub. If your API is SOAP or returns XML, review the recommendations for how to minimize the impact on your system from making API calls from SNIPPET.

Las Dependencias

  • Code used in this action must be written in Snippet, an in-house scripting language developed for NiCE CXone. The Studio technical reference guide provides detailed information about scripting in snippets.
  • Attributes of dynamic data objects cannot be named __type (with two underscores). This word is reserved for use when parsing JSON from dynamic objects.
  • You can make API calls using the Snippet action. However, this is not the recommended method of making API calls in your scripts. If you do make them in this way, be sure to understand the risks and best practices.
  • El tamaño máximo de las matrices en Studio es de 63 millones de elementos. Exceder este tamaño de matriz genera el siguiente error en la variable __err en un seguimiento de script: Índice de matriz fuera de límites. El índice de la matriz actual ([índice]) excede el índice máximo permitido (63000000). When the array size is exceeded, the script takes the SNIPPET action's Error branch. If the Error branch is not connected, the script continues to run, but without the array information. You can configure scripts to notify you when the maximum array size has been exceeded by adding an EMAIL action to the SNIPPET action's Error branch. Finally, you can add logic in the Error branch to continue to the script. Note that it will continue without the array information.
  • The maximum response size in NiCE CXone is 32 KB. The limit is strictly enforced to prevent cluster instability and outages. Studio enforces this limit when saving the script, but Desktop Studio does not. If you can, use the REST API action or Integration Hub instead of the SNIPPET action to make API calls. They have the same limit, but can handle a heavier load. If you must use the SNIPPET action, follow these tips to reduce the size of the returned data: 

    • Filter the data in the API response: For example, if you're using the NiCE reporting API to get contacts, you can filter the results by the startDate and endDate of the contact. This API call also allows you to return and limit a top count of items. Refer to the API documentation that came with your script integration to determine what filtering you can use.

    • Update the API request to return only the data you need: For example, if you're using the NiCE reporting API to get contacts, you can use the contactId or agentId fields to return only relevant data. Refer to the API documentation that came with your script integration to determine what data limits you can use.

    • Build middleware: If you cannot do either of the previous options, build middleware that does filtering based on custom criteria you define. If you do this, ensure that your middleware does not add latency to the call.

  • Every FOR, FOREACH, or REPEAT loop within a SNIPPET is protected by a 500 ms time limit. If a loop exceeds this limit, the SNIPPET action takes the error branch with the error Too much time has elapsed. This prevents the use of excessive system resources for runaway loops. The 500 ms time limit applies only to script-side work, including assignments, arithmetic, conditions, array access, and so on. It does not apply to the end-to-end running of the snippet code. For example, time spent waiting for an external system such as a REST API or database call does not count against this limit.

Tipos de secuencias de comandos compatibles

The icon for a Generic script type - a rectangle with < and > symbols inside it.

The icon for the Email script type - a large @ symbol in a diamond.

The icon for the Chat script type - a chat bubble with an ellipsis inside (...), in a diamond shape.

The icon for the Phone script type - an old-style phone handset with curved lines indicating sound coming out of it.

The icon for the Voicemail script type - a symbol that looks like a cassette tape - two circles sitting on a horizontal line.

The icon for the Work Item script type-a piece of paper with one corner folded down and a bullet list on it.

The icon for the SMS script type - a smart phone with a chat bubble coming out of it.

The icon for the Digital script type - a computer monitor with a smartphone next to it.

Generic

Email Chat Phone Voicemail Work Item SMS Digital

Propiedades de Entrada

Estas propiedades definen los datos que utiliza la acción al ejecutarse.

Las propiedad

Descripción

Caption

Ingrese una frase corta que identifique de forma única esta acción en el script. La leyenda aparece en el lienzo del script debajo del ícono de acción. The default is the action name.

Data

Contiene el código personalizado que se agregó en la ventana Snippet editor. Esto puede incluir varios comandos ASSIGN y DYNAMIC, declaraciones de control de flujo distintas y funciones integradas y definidas por el usuario.

MaxStringSize

Define el tamaño máximo de cadena para todos los comandos en la propiedad Data. Las opciones son: Limit2K, Limit4K, Limit8K, Limit16K, Limit32K. Se aplica este límite a las respuestas de integración con las Rest API y SOAP.

Condiciones de la rama de Resultado

Las condiciones de las ramas de resultados le permiten crear ramas en su script para manejar diferentes resultados cuando se ejecute una acción.

Condición

Descripción

Default

Recorrido a menos que el script cumple una condición que requiere uno de los otros poderes. También se considera si no están definidas las demás ramas de la acción.

OnError

Ruta tomada cuando la acción no se ejecuta correctamente. Por ejemplo, cuando haya un problema inesperado como una mala conectividad, errores de sintaxis, etc. La variable _ERR, con un único carácter de subrayado, debe llenarse con una explicación condensada del problema.

Tenga cuidado al realizar llamadas de API desde SNIPPET

Building API calls within a snippet is not recommended. It may lead to serious performance issues that impact contact handling and negatively impact your tenant. For a more secure and reliable experience, use one of the following preferred methods.

There are two cases where making calls from SNIPPET is the method you must use: if you're connecting to a SOAP web service or if your API calls include XML. If you must use SNIPPET for API calls: 

  • Limit timeouts in your API calls. A general recommendation is that timeouts be no more than two seconds. The default timeouts may be longer, so always verify the timeouts to ensure that they do not exceed this maximum. If you find that longer timeouts are required, adjust your web service if possible to improve its response times.
  • Be extremely careful with loop logic. The combination of loops and long timeouts compound the potential impact on your system.
  • The maximum response size in NiCE CXone is 32 KB. The limit is strictly enforced to prevent cluster instability and outages. Studio enforces this limit when saving the script, but Desktop Studio does not. If you can, use the REST API action or Integration Hub instead of the SNIPPET action to make API calls. They have the same limit, but can handle a heavier load. If you must use the SNIPPET action, follow these tips to reduce the size of the returned data: 

    • Filter the data in the API response: For example, if you're using the NiCE reporting API to get contacts, you can filter the results by the startDate and endDate of the contact. This API call also allows you to return and limit a top count of items. Refer to the API documentation that came with your script integration to determine what filtering you can use.

    • Update the API request to return only the data you need: For example, if you're using the NiCE reporting API to get contacts, you can use the contactId or agentId fields to return only relevant data. Refer to the API documentation that came with your script integration to determine what data limits you can use.

    • Build middleware: If you cannot do either of the previous options, build middleware that does filtering based on custom criteria you define. If you do this, ensure that your middleware does not add latency to the call.

Consejos y trucos

Snippet Editor Ventana

La ventana Snippet editor se abre cuando hace doble clic en una acción Snippet.

La ventana Snippet editor en la acción Snippet tiene dos pestañas. Ambas pestañas le permiten crear los mismos tipos de código. Puede alternar entre pestañas y editar su código en cualquier lugar. Las pestañas son:

  • La pestaña Vista de Texto. Este es un campo de texto de formato libre donde puede escribir manualmente su código.
  • La pestaña Vista de Árbol. Esta es una interfaz gráfica que puede utilizar para crear su código. Esta pestaña tiene una lista desde la que puede seleccionar palabras clave para agregar declaraciones al snippet.

Ejemplo de Script

Este es un ejemplo para demostrar cómo se puede utilizar esta acción en los scripts. No pretende ser un script completo. Es posible que se requiera programación adicional.

En este simple ejemplo, el código en el Retazo se utiliza para probar si un cliente potencial puede crearse utilizando información de un sistema de terceros.

A script with two SNIPPET actions.

Descargar este script.