SNIPPET

Provides an environment in which to create and add custom code to your script.

Supported Script Types

Generic Email Chat Phone Voicemail Work Item SMS

Properties

Data
Multiple ASSIGN commands with an assortment of flow control commands.
MaxStringSize
Sets MaxStringSize for all ASSIGN commands contained within the Data property: Limit2K, Limit4K, Limit8K, Limit16K, Limit32K.

Branches

Default
The Default branch condition follows the SNIPPET action.
OnError
This branch will be followed if an error occurs.

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)

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.
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.
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 if testing within inControl, or does nothing if using on the production platform.
// <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. See below.

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, a 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.
  • asgmtasutc converts 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 2009 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.

  • 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.