Snippet

Allows you to add custom code to your script.

Dependencies

  • Code used in this action must be written in Snippet, an in-house scripting language developed by NICE CXone. Reference material for using Snippet is available in the Studio online help.
  • 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. The maximum response size is 32 KB. This is consistent with the response size limit in the REST API action.

Supported Script Types

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

Properties

Property Details
Data

Multiple ASSIGN commands with an assortment of flow control commands.

MaxStringSize

Sets the maximum string size for all ASSIGN commands in this Data property: Limit2K, Limit4K, Limit8K, Limit16K, Limit32K.

Branches

Branch Details
Default Path taken unless the script meets a condition that requires it to take one of the other branches. It is also taken if the action's other branches are not defined.
Error Path taken when the action fails to execute properly. For example, when there is an unexpected problem (for example, poor connectivity, syntax errors, and so forth). The _ERR variable (with a single underscore character) should be populated with a condensed explanation of the problem.

Tips & Tricks

  • Use the asjson() function in a Snippet action and store the resulting JSON in a string variable. Use the string variable in the properties of other Studio actions when you need to pass the JSON data. This approach avoids the possibility of validation errors when saving the script.

Snippet Commands

Snippets are made up of several commands, some of which mimic the Studio action of the same name. These commands are accessed by opening the Snippet Properties window, clicking the Tree View tab, and then clicking the green plus sign at the bottom of the window (or you can click the Text View tab to input your code manually). See the Flow Control Command Set page for more information.

The following table lists the commands with a brief description:

Command Description
ASSIGN <name>=<value> Allows a variable to be assigned a value. The syntax of the value matches the syntax supported by the Assign script action.
DYNAMIC Creates a dynamic data object.
IF <expression> { … } [ ELSE { … } ] Evaluates an expression and performs appropriate commands based on the results. The expression matches the syntax supported by the IF script action.
Global 

Creates a global variable in a subscript. Use this syntax: 

ASSIGN global: varName
REPEAT <value> { … [ BREAK ] } Performs the designated commands a specified number of times.
SWITCH <value> { CASE <literal> { … } [ CASE <literal> { … } ] [ DEFAULT { … } ] } Performs a set of commands based on the value.
SELECT { CASE <expression> { … } [ CASE < expression > { … } ] [ DEFAULT { … } ] } Performs a set of commands based the first expression to evaluate to true.
FOREACH <var> in <array> { … [ BREAK ] } Repeats a loop once for each element in an <array>.
FOR <var> = <start> to <end> { … [ BREAK ] } Repeats a loop for the values in a range.
FUNCTION <name>([<parameter>[,<parameter>][…]) { … [ RETURN <data> ] } Declares a reusable function.
<name>([<parameter>[,<parameter>][…]) Calls a reusable function.
TRACE “<text>” Outputs text to the result window of the Snippet Properties window.
// <comment text>

Marks a section of text as a comment.

You can comment multiple lines of code at the same time in the Snippet action.

Snippet Properties Window

The Snippet Properties window is a specific window that you use to add your code.

To open the Snippet Properties, just double-click the Snippet action on your canvas. From the image above, you can see that you can develop your code in one of two ways - through the Tree View or through the Text View. With the Tree View, you can use the features at the bottom of the window to add commands to your code, whereas with the Text View, you can write code the same as if you were developing in Notepad or other simple text editors.

Phone Script Example Using Snippets

In this simple example, the code in the Snippet is used to test whether a prospect can be created using information from a third-party system.

Would you like to download this script?

Sample Snippets

  • append adds the text to the end of the existing contents within the variable.
  • astime converts the contents of the variable to the time string.
  • asdate converts the contents of the variable to a date string.
  • asdatetime converts the contents of the variable to a date and time string.
  • asdatedow converts the contents of the variable to an OLE automation date/time by parsing the string contents and then returns the day of the week as an ordinal value from 0 to 6 where 0 is Sunday.
  • asgmt and asutc convert the contents of the variable to a date/time string formatted TO RFC 1123 which is “ddd, dd MMM yyyy HH:mm:ss gmt”. For example: “Mon, 03 Oct 2022 13:35:14 gmt”.
  • char returns a character from the ASCII code value, which enables a script to programmatically add special characters to a string (i.e., carriage returns and tabs).
  • contains returns a value of '1' (true) if the variable contains a specified value. If the variable is an array, all the elements will be checked for the exact value.
  • count/size returns the number of elements within any array. If the value is not an array but is not empty, the value '1' (true) is returned; otherwise, the value '0' (false) is returned.
  • dateadd returns a new date based on the original date plus a value in either OLE automation format or as a string formatted date. The interpretation of value is determined by the unit.
  • datediff returns the difference between two dates.
  • datefmt converts the contents of the variable to a date and time string using custom formatting.
  • datepart returns a portion of a date or time.
  • datebuild returns a date formatted in standard date/time format.
  • datetimebuild returns a date/time formatted in standard date/time format.
  • dow returns the day of week as an ordinal value from 0 TO 6 where 0 is Sunday.
  • dynamic data object creates a user-defined object that can be used in the script or actions that require an object input value.
  • floorceil returns the largest integer less than or equal to the specified value.
  • for repeats a loop for the values in a range.
  • foreach repeats a loop once for each element in an <array>.
  • format returns a string that is formatted using the specified format, which applies only to the numeric value contained within the variable.
  • function declares a reusable function.
  • hash returns an encrypted string of an existing variable, using the following encryption methods:
    • MD5
    • SHA-256 (SHA-2, 256-bit)
    • SHA-384 (SHA-2, 384-bit)
    • SHA-512

    These methods support UTF-8, UTF-16, Base64, and HMAC encodes in little endian format. RSA encryption methods are not supported at this time.

  • if evaluates an expression and performs appropriate commands based on the results. The expression matches the syntax supported by the If script action.
  • index returns the specified array element within the variable.
  • indexof returns the character position of the text as contained within the variable. The first position is 1. If the text is not contained, a '0' value is returned.
  • isalphaisnumeric returns '1' (True) if all characters within the variable are letters of the alphabet (A-Z, a-z). Otherwise, '0' is returned. An empty variable returns '0.'
  • isdigitisletter returns '1' (True) if the first character within the variable is a numeric digit (0-9). Otherwise, a '0' (False) is returned. Also, returns a '1' if the first character within the variable is a letter of the alphabet (A-Z, a-z). Otherwise a '0' is returned.
  • isupperislower returns '1' (True) if the first character of the variable is an uppercase letter. Otherwise, '0' (False) is returned. Also, returns '1' if the first character of the variable is a lowercase letter. Otherwise, it returns a '0.'
  • left(count)right(count). left(count) returns the left-most count characters; right (count) returns the right-most count characters.
  • length returns the length of the textual representation of the variable's value. For instance, if the value is a number like 1234.56, the length will be 7.
  • mid. String expression returns the characters from start through start + length. The first character position is 1. If start + length exceeds the length of the source text, the source text will be truncated. Numeric expression takes the characters from start through start+length and tries to read them as a number. If the characters do not represent a number, 0 will be returned instead.
  • minmax. Min returns the smaller of the two values specified. Max returns the larger of the two values specified.
  • random returns an integer non-negative random number greater than or equal to zero and less than the specified maximum value.
  • replace substitutes all occurrences of an old value with a new value.
  • round returns the value rounded to the nearest integer using IEEE Standard 754, section 4 (also called Banker's Rounding).
  • select performs a set of commands based the first expression to evaluate to true.
  • sizecount returns the number of elements within the array if the variable contains an array. If the value is not array and is not empty, then '1' (True) is returned. Otherwise, '0' (False) is returned.
  • split returns the contents of the variable as a pipe delimited string suitable to be treated as an array. The delimiter will be converted to the pipe (|) symbol.
  • substr. String expression returns the characters from start through end. The first character position is '1.' If end exceeds the length of the source text, it will automatically truncate at the end of the source text. Numeric expression takes the characters from start through end and tries to read them as a number. If the characters do not represent a number, '0' will be returned instead.
  • switch performs a set of commands based on the value.
  • trimltrimrtrim. Trim returns a string with all leading and trailing white space characters removed. White space includes spaces, tabs, and line breaks. Ltrim returns a string with all leading white space characters removed. Rtrim returns a string with all trailing white space characters removed.
  • upperlower. Upper returns the contents of the variable with all letters converted to uppercase. Lower returns the contents of the variable with all letters converted to lowercase.
  • urlencode urldecode. Urlencode returns the contents of the variable encoded using the Internet standard FOR URL encoding. Some data that needs to be added to a URL for sceenpops needs to be encoded for it to be sent correctly. Urldecode returns the contents of the variable decoded from the Internet standard FOR URL encoding. In this example we are simply decoding the URL we just encoded, which means URL and NewURL have the same value.