ECMAScript Expressions

From Genesys Documentation
Jump to: navigation, search
This topic is part of the manual Designer User's Guide for version Current of Designer.

In certain blocks, you can use ECMAScript expressions to perform dynamic operations while an application is running. For example, you can use ECMAScript expressions to assign values to variables or perform certain functions, like sorting an array.


Before you start

To use this feature, you must have a basic level of familiarity and understanding of ECMAScript syntax and rules.

Although the terms ECMAScript and JavaScript are often used interchangeably, Designer technically supports ECMAScript and does not support JavaScript functions that are typically used for web-browser based applications, such as pop-up windows, alerts, and so on.

Designer blocks that support the use of ECMAScript expressions include:

In general, block properties do not support ECMAScript expressions unless otherwise stated. If ECMAScript expressions are not supported, you must enter a value (a string that is taken as a literal). This value is not evaluated at runtime. For example, in the Play Message block, the value of a TTS prompt is interpreted as a literal string.
Warning
Due to certain platform dependencies and limitations, not all ECMAScript functions are supported when used in Designer. For example, the toLocaleString function is not supported at this time.

A few notes on syntax

Some rules and guidelines to follow when using ECMAScript in Designer:

  • Strings must be quoted ('). For example, 'hello' is a string, whereas hello is a reference to a variable called hello.
  • Single quotes (') are recommended, as opposed to double quotes (").
  • When specifying an object in JSON notation, surround the JSON with parentheses. For example: ({'abc': 'def'}).

Use caution! Any errors in your script can cause erratic behavior, so test your changes to make sure that your script works correctly before running it in your production environment. Designer can check your script for syntax errors, but cannot validate it nor check for runtime errors that might occur when the script is executed.

Examples of how ECMAScript can be used

Below are examples of how ECMAScript expressions can be used in Designer applications.

Building a Dynamic TTS Prompt

You can use the Assign block to concatenate a string to be spoken by the application. For example, the expression below reads the caller's phone number or ID:

'You are calling from ' + ANI

Controlling the Application Flow

A Segmentation block can take ECMAScript expressions that evaluate to a Boolean value, and thus control the flow of the application.

For example, you might want to inform your customers about upcoming seasonal events and you need a way to determine the current season and whether the event is occurring within the coming week. The expression below determines whether the call was received within seven days of the event, and whether the current season is summer or autumn:

numDays > 7 && (isSummer | | isAutumn)

Advanced scripting in Designer

In blocks where it is supported, you can use use the Advanced Scripting tab to compose more complex ECMAScript constructs, such as loops or multiple nested conditions.

Let's take a look at how advanced scripting could be used to assign a value to a variable. Here, some script has been added to the Advanced Scripting tab of an Assign Variables Block:

Des assignvar advanced ex2.png

In this example, the script sets the variable varOrdersPrompt to 3 Laptop bags, 2 Phone chargers, 1 Super rare fish.

Here's how it works:

The sample script first initializes JSON data in varOrderDetails so that it becomes an array of three JSON objects. Each JSON object has properties — item, quantity, and backordered. The script then proceeds to loop through orders and forms a string to play back to the caller to notify them of their order status.

The script uses variables in two scopes:

  • A scope exclusive or local to this script itself (i). This variable remains available only while this script runs, and then it disappears.
  • Top-level variables that were defined in the Initialize phase remain available throughout this application flow, but not in any modules this application calls (such as varOrdersPrompt).
Important
Advanced Scripting is an optional feature and might not be enabled on your system. To enable this functionality, contact Genesys.


Built-in user functions

Designer also has built-in ECMAScripts that you can invoke from a Designer application, such as from an Assign or Segmentation block, to perform certain functions at runtime.

isDataTableValueValid

You can use this function to determine if a value returned from a data table query is valid. For example, you might use the following function in an Assign block:

isDataTableValueValid(value, datatype)

This function has two arguments:

  • value is a single value returned from a data table query
  • datatype is the data type of the data table column, such as 'string', 'boolean', 'integer', 'announcement', or 'numeric' (this argument is optional)

If the data table value is valid, the script returns true. Here is a list of values that this function can return:

  • isDataTableValueValid(varStr, 'string') on a valid (or empty) string returns true. Anything else returns false.
  • isDataTableValueValid(varNum, 'numeric') on a valid number or 0 returns true. Anything else returns false.
  • isDataTableValueValid(varNum, 'integer') on a valid integer or 0 returns true. Anything else returns false.
  • isDataTableValueValid(varBool, 'boolean') on true or false returns true. Anything else returns false.
  • isDataTableValueValid(varAudio, 'announcement') on a valid (or null) announcement returns true. Anything else returns false.
Retrieved from "https://all.docs.genesys.com/DES/Current/Designer/ECMAScript (2021-09-19 07:46:29)"