Commonly used Actions

Actions are the backbone of the scripting capability in the TIVITY platform. This article lists and described a few commonly used Actions and provides examples of use.

Block

The Block action allows the grouping of elements in logical units. It is usually used to assign a list of the same operation to a higher-level unit.

Use of Block statements to separate a script into logical units

The example above has a Block element in which variables are assigned and another Block element in which operations are performed with those variables. See also Architecture of a Script for more explanation.

Variables

Variables are commonly used to handle flexible script execution. A variable can be defined as a constant value or might hold the return of a called function. During script execution variables can be used in other actions.

Example 1: Create a variable and assign a constant value

In the Scripting Area click into the Drop statement here block and enter variable in the appearing search box. The Action menu is going to show you the Variable action. Select the Action to add it to the script.

Next, enter a Name for the newly created statement, e.g. FY2021Begin to indicate the begin of the financial year 2020/21. That name value is going to be listed in the Variables Menu and allows easy reference and use at a later stage in the script.

Then click into the Expression (Any) area to specify the data type of the variable, e.g. DateTime. The search feature assists you to find and choose the data type.

Last, provide a value for the variable to complete the statement, e.g. 01.07.2020.

Create a constant variable in the Script Designer

The newly created variable appears in the Variable Menu on the right-hand side of the Script Designer as soon as the data type in the Expression field has been specified. The variable can be used for other operations in the script.

Example 2: Create a variable and assign an object

In the Scripting Area click into the Drop statement here block and enter variable in the appearing search box. The Action menu is going to show you the Variable action. Select the Action to add it to the script.

Next, enter a Name for the newly created statement, e.g. Context to indicate the runtime context of the script. The variable is going to be listed in the Variables Menu and allows easy reference and use at a later stage in the script.

Then click into the Expression (Any) area and enter getinstance in the appearing search box. The result list is going to show you the GetInstance action which has a return type of Object. The GetInstance action is normally used in an instance workflow. As a reminder: “An instance workflow is a workflow that is called-up for a specific object.” The “Context” part refers to this object.

Finally, drag and drop the corresponding, built-in variables from the Variables Menu into the properties of the GetInstance expression to complete the newly created variable.

Create a variable using the GetInstance action in the Script Designer

An Object returned by GetInstance action is identified by the following fields.

Property

Description

OfficeId (Guid)

Indicates the ID of the workspace in which the application is located and for which a workflow is created.

ApplicationId (Guid)

Indicates the ID of the application located in the selected workspace.

ClassId (Guid)

Indicates the ID of the class that identifies the object.

InstanceId (Any)

Each object has a unique ID. To reference a specific object, the specific ID can be entered here.

LinkPath (LinkPath)

The LinkPath is the navigation path to an object. It describes the steps that led to the object.

Example 3: Reference a variable

After creating variables and assigning values or objects to them, it is time to work with those variables. To illustrate this, take the subtraction of two numbers.

First define two variables Number 1 and Number 2 as described in Example 1: Create a variable.

Then add the Subtract action to the script and drag the two variables from the Variables Menu on the right-hand side to the desired place in the statement.

Get values of variables in an action

The choice of Get or Set operation defines how the value of a variable is used in a script (see green boxes above).

GetCurrentUser

Many scripts require information from the user who initiated the script, i.e within a workflow. In order to interact with the user on the TIVITY platform get the user object using the GetCurrentUser action and save it in a variable called User.

A user is uniquely identified by an office. Therefore select the Context.OfficeId variable from the Variables Menu.

Get the current user and store it in a variable

Now, it is possible to work with the user object just like with any other object and, i.e. use the GetValue action to read out a user’s ID.

Working with Values

Compared to variables Values are associated with an object. The two actions GetValue and SetValue allow you to read a field of an object and to define a new value for a field.

GetValue

The GetValue action allows to read a value from a field of an object. The action has two parameters. Object (Object) identifies the object from which the value is to be read. Field (String) is the property of the object which holds the value. The terms in parentheses indicate the expected data type.

Read the Field (Id) of an object

The example above uses the GetValue action from the Actions Menu. Then, drag the “Object” object previously defined from the Variables Menu into the Get Variable area. Next, enter the word “Id” in the text box next or under Field.

Field is case-sensitive, i.e. upper case and lower case are important here.

Field denotes the field of an object. This means that it is possible to look up the key of a field in an object in the class designer. An alternative way to access a Field is described under GetSystemName.

SetValue

In comparison the SetValue action allows values to be set in a field of an object. The two parameters Object and Field are equivalent to the GetValue action. The third parameter Value is the actual value to be stored in the field.

In order to be able to set a value to an object you need to hold a reference to it. The action GetInstance provides you access to such an object reference, as described in Example 2: Create a variable and assign an object.

Set or update the value in a field (Description) of an object (Note)

In the example above you get a reference of an Object of type Note using a variable. Next, the script is going to update the Field Description with the information provided in the Value expression.

This example was greatly simplified. In a real scenario, the user should be able to enter a value on the UI, and the script should represent the logic to store this value.

GetSystemName

The GetSystemName action allows you to look up the names of fields of a class directly in the Script Designer. This eliminates the need to go into the Class Designer just to look up the name of a field.

Use GetSystemName to reference a field and set a new value

The example shows how to set a value to a variable Note of type Object. It uses the GetSystemName action to reference the field Description of an object (here: Unit).

GetSystemId

Just as with the GetSystemName action, the GetSystemId action allows you to fetch the Ids. A list of available classes, fields, actions, workflows etc. can be used to search for a specific name. If you don't know the name, you can also search for the type, e.g. with the search word 'class' all classes are listed. In addition, if you enter e.g. 'controller', all controllers will be listed.

Script helper GetSystemId

Available ID lists

  • Class

  • Field

  • Action

  • Workflow

  • Layout

  • Query

  • Script

  • Template

  • Function

  • Link

  • LinkServiceType

  • Controller

  • Group

  • Office

  • Feature

Last updated

Was this helpful?