Teneo Developers

Global Scripted Contexts


The Global Scripted Contexts enable Teneo users to define context scripts to ensure that the end-user of the application is presented with the correct answer based on the context of a dialogue.

Global Scripted Contexts can be written and maintained by script-savvy users while other users easily apply them throughout the solution without needing to know how they work or how to script. All Scripted Contexts are defined and maintained in the backstage of Teneo Studio and can be used in Flows whenever needed.

View of Global Contexts

The Global Scripted Contexts are available in the backstage of Teneo Studio: Solution tab > Globals > Contexts.

View of Global Scripted Contexts

In this view, the user will find:

  • Left side:
    • Text filter and Add button
    • List of existing Global Contexts
  • Right side:
    • Ribbon options allowing to Edit, Search, view History, set/unset Stable version, include/exclude in Branching
    • Details of the selected context providing a read-only summary
    • Global Context's Id

Scripted Context window

The Global Scripted Context window is accessed by either adding a new context or by editing an existing context.

Global Scripted Context window

The Scripted Context window has two tabs:

  • Scripted Context tab providing access to the Properties and History
  • Home tab with
    • Top ribbon
    • Script editor
    • Right-side panel with Expected state(s)

For more details see the Edit section further below.



To open a Global Context from the backstage of Teneo Studio, simply double-click the Context; alternatively select the Context to open and click Edit in the ribbon in the upper right side of the window.


To create a Global Context, follow the below steps:

  • Go to Global Contexts in the backstage of Teneo Studio (Solution tab > Globals > Contexts)
  • Click Add in the ribbon
  • The new Scripted Context window opens
  • Give the Global Context a Name and optionally a Description
  • Click Change image... to upload a customized icon to represent the context in Studio
  • Click the back-arrow in the top left corner
  • In the main view, write the execution script in the Script editor and add the expected states in the left-side panel
  • Remember to click Save in the top ribbon to preserve the changes.


To edit a Global Context, select it in the list of Contexts and click Edit in the right side of the window; alternatively double-click the name to open the Context.
After opening the Global Context, it is possible to modify the script or other details (e.g. the name, description, image, etc.); below please find an overview of the available options and buttons.

If a Context is already opened in edit-mode, the Edit button is replaces with a Go to button for the user to navigate directly to the Context window.

Global Context: top ribbon

The Global Scripted Context's top ribbon provides the below specified buttons.

SectionButtonCommentMore information
Scripted ContextCloseClose the Global Context window
SaveSave the Global Context in the current state; clicking the lower part of the button allows the user to save the Context with or without a comment
ScriptOpen with...Allows to open the context in an external script editor; when the button is clicked for the first time the user is prompted to select the script editor
EditUndo/RedoUndo/redo changes performed in the Global Context
Stable VersionSet/UnsetSet the current version of the Global Context as stable or unset itVersion flag
BranchingInclude/ExcludeInclude or exclude the Global Context from branching when working in a Localization setupLocalization setup

Scripted Context tab

The Scripted Context tab allows to access the backstage of the Global Context window where the following options are available.

Menu itemCommentMore information
SaveSave the Global Context in the current state
PropertiesAllows to edit the name, description and images of the Global Context; the Id of the document is also displayed here
HistoryLists the history and versions created each time the Global Context is saved, comments added at save are displayed here. Open a previous version by clicking the version number; restore a previous version by opening the specific version and clicking Restore in the top ribbonVersion history
CloseClose the Global Context window

The name, description and icons of a Context are used throughout Teneo Studio; therefore it is recommended to chose a representative name/icon as well as write a description of its meaning and usage.


To save a Scripted Context with a comment, follow the below steps:

  • Click Save in the top ribbon of the Context window
  • In the dialogue box (optionally) write a comment
  • Click Continue
  • When Teneo Studio confirms the save, click Close.

To save directly and bypass the comment, press the Alt key while clicking the Save button.

Clicking the lower part of the Save button allows to select between Save with comment and Save without comment

Note that it is mandatory to give the Context a Name, write a Context script and add at least one expected state; Teneo Studio will prevent save if either is missing.


The Global Context window can be closed by performing one of the following actions:

  • Click the X in the top, right corner of the window
  • Click the Close button in the top ribbon
  • In the Scripted Context backstage, click Close in the left-side menu

In case of unsaved changes, Teneo Studio prompts the user to Save Changes or Discard Changes.


To delete a Global Context, follow the below steps:

  • In the backstage of Teneo Studio (Solution tab > Globals > Contexts), select the Context to delete
  • Click Delete in the ribbon
  • Teneo Studio prompts the user to confirm the deletion, click Yes
    • If the Context is in use, the Items In Use message is displayed, select the Context to delete and click Continue to confirm the deletion. Alternatively, click Continue without selecting any Context to abort the deletion
  • A confirmation is displayed, click OK to continue work in Teneo Studio.

If a Global Context is deleted by mistake, it can be restored from the Recycle Bin.


A text filter is available at the top of the list of Global Context; to filter on the available contexts, simply write the wanted letter combination to start filtering on the list.

This section currently only apply toTeneo Studio Desktop

To search for the usage of a Global Scripted Context in a solution, follow the below steps:

  • In the backstage of Teneo Studio (Solution tab > Globals > Contexts), select the Scripted Context
  • Click Search in the ribbon
  • The Search results are automatically opened in the frontstage of Teneo Studio


Definition and execution

A Global Context consists of a script and a set of expected states and are assigned as Matches to either triggers or transitions; once defined these scripts are executed at runtime calculating the current state of the defined context and testing it against the expected states. If successful, the trigger/transition is set off. By using context, the trigger and transition depend both on the established Matches and the scripted states.


The main part of a Global Context is the script which defines how the context state should be determined. When executed at runtime, it will return a value representing the current state of the dialogue at the point when the assigned context is tested. The value returned by the scripted context definition can be any Groovy type or any custom type which can be usefully compared with Groovy's equal operator ==.

Multiple assignments

Assigning multiple context states to a Match of a trigger/transition will apply the context with an OR operator; for example: LatestTopic is Weather OR Directions OR Maps.

Assigning multiple Contexts to a Match of a trigger/transition will apply the context with an AND operator; for example: LatestTopic is Weather AND UserLocationIsKnown.