Sequence operators can easily extract an attribute value from the first, last, or other specific element in a sorted collection (see First, Last, or At for examples). This is especially useful when the attribute's value is involved in a comparison in a conditional or preconditional rule. Sometimes, however, you want to identify a particular element in a sequence and flag or tag it for use in subsequent rules. This can be accomplished using special syntax called statement blocks.

Statement blocks, permitted only in the Action rows of the Rulesheet, use special variables, prefixed by a question mark character (?) to hold or pin an element so that further action can be taken on it, including tagging it by assigning a value to one of its attributes. These special holder variables can be declared when needed, meaning they do not need to be defined anywhere prior to use.

For example, in a sales management system, the performance of sales representatives is analyzed every quarter, and the highest grossing sales representative is awarded Salesperson of the Quarter. This special status is then used to automatically increase the representative's commission percentage on sales made in the following quarter. The generic Vocabulary used in previous examples is used, but with these assumptions:

Vocabulary Term Meaning
Entity2 A salesperson
Entity1.entity2 Collection of salespeople
Entity2.string1 A salesperson's name
Entity2.decimal1 A salesperson's quarterly sales
Entity2.string2 A salesperson's award
Entity2.decimal2 A salesperson's commission percentage

Using this Vocabulary, construct the following Rulesheet:

Figure 1. Rulesheet using statement block to identify and reward winner

Important Notes about Statement Blocks

As expressed in Action row A in the preceding figure, a statement block consists of two separate expressions:

  1. The first part assigns an element of a sequence to a special holder variable, prefixed by the ? character. This variable is unusual because it represents an element, not a value. Here, the highest grossing salesperson is expressed as the last element of the collection of salespeople (e2), sorted in ascending order according to quarterly sales (decimal1). Once identified by the sequencing operator ->last, this salesperson is momentarily held by the ?tag variable, which was declared when it was needed.
  2. The second part of the statement—the part following the semicolon—assigns a value to an attribute of the element held by the ?tag. In the example, a value of 'Salesperson of the Quarter' is assigned to the string2 attribute of the salesperson held by ?tag. In effect, the highest grossing salesperson with this award is tagged.

These two parts must be included on the same Action row, separated by a semicolon. If the two parts are separated in different sections or in different rows of the same section, then the element represented by the ? variable is lost. In other words, the ?tag loses its grip on the element identified by the sequencing operator.

Note: Using semicolons: The semicolon is an action statement end character that creates a compound action statement., Each action statement is executed sequentially. Its use, however, can make it harder to read action statements in Rulesheets and reports. It is a good practice to use semicolons only when there is no alternative, as in this example.

Now that the winner has been tagged, you can use the tagged element (awardee) to take additional actions. In the Conditional rule, the commission percentage of the winner is increased by 5% using the Increment operator.

The next figure shows a Ruletest Input and Output pane. As expected, the highest grossing salesperson was awarded Salesperson of the Quarter honors, and their commission was increased by 5%.

Figure 2. Output panel with winner and adjusted commission in bold