skip to main content
Corticon Studio: Rule Modeling Guide : Collections : Statement blocks
 

Try Corticon Now

Statement blocks

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 ? character, to hold or pin an element so that further action may be taken on it, including tagging it by assigning a value to one of its attributes. These special holder variables may be declared on the fly, meaning they do not need to be defined anywhere prior to use.
Here's an example. In a sales management system, the performance of sales reps is analyzed every quarter, and the highest grossing sales rep is awarded Salesperson of the Quarter. This special status is then used to automatically increase the rep's commission percentage on sales made in the following quarter. We will use the same generic Vocabulary as in all previous examples, but make 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, we construct the Rulesheet shown in
Figure 109. Rulesheet using Statement Block to Identify and Reward Winner

Important Notes about Statement Blocks

As expressed in Action row A in the figure above, 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 we declared on-the-fly.
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 our example, we are assigning a value of 'Salesperson of the Quarter' to the string2 attribute of the salesperson held by ?tag. In effect, we have tagged the highest grossing salesperson with this award.
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, the element represented by the ? variable is lost, in other words, ?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 recommended that you use semicolons only when there is no alternative, as in this example.
Now that we have tagged our winner, we can use the tagged element (awardee) to take additional actions. In the Conditional rule, we increase the commission percentage of the winner by 5% using the Incrementincrement operator.
The next figure shows a Ruletest Input and Output pane. As expected, our highest grossing salesperson has been awarded Salesperson of the Year honors, and has had her commission raised by an additional 5%.
Figure 110. Output Panel with Winner and Adjusted Commission in Bold Black Text