Copyright © TIBCO Software Inc. All Rights Reserved


Chapter 15 Rules and Rule Functions : Adding a Rule

Adding a Rule
These instructions focus on the form-based editor and mention the equivalent settings in the source editor. Adapt the instructions if you are using the source editor.
Figure 2 Rule Form Editor
Figure 3 Rule Source Editor

 
 
* @description
* @author
*/
rule Rules.ProcessDebits.ApplyDebit {
  attribute {
    priority = 1;
    forwardChain = true;
Optionally add entry for Rank as needed (Rank=RuleFunction), or enter in Form view.
 
  }
  declare {
    Events.Debit  debit;
    Concepts.Account  account;
 
  }
  when {
    //Checks whether the extId of an Account instance in working memory
    //matches the incoming event's account ID
    account@extId == debit.AccountId;
  }
  then {
    //If Account Status is not Suspended, debits the account
    if (account.Status !="Suspended") {
    account.Debits=debit.Amount;
    System.debugOut("############### Debiting account <" +account@extId+ "> by $" +debit.Amount);
    account.Balance=account.Balance - debit.Amount;
    System.debugOut("############### New balance: $" + account.Balance);
    }
    else {
    System.debugOut("############### Cannot debit the suspended acount <" +account@extId +">");
    }
    Event.consumeEvent(debit);
  }
}
  

 
To Add a Rule
See Rule Editor Reference for details on the settings.
1.
2.
In the Rule Name field, type a name for the rule. In the Description field, type a description as desired. (In the source editor the description appears in the @description line of the comments at the top of the editor.)
You can’t change the name in the editor. To change the name of any project element, right-click the element in Studio Explorer and select Refactor > Rename. See Chapter 4, Element Refactoring Operations for more details.
3.
Click Finish. By default, you see the source rule editor on opening the editor. It shows the outline for a rule’s source code. Click the Form tab at the bottom of the editor to use the form editor.
At any time you can click the Form and Source tabs at the bottom of the editor to switch between the form-based editor and the source editor as you work, depending on your preference.
Rule Editor Preference  To set which mode the editor uses upon first opening, go to Window > Preferences > TIBCO BusinessEvents > Rules and check or uncheck the following checkbox as desired: Initially show ’Form’ tab in Rule Editor
4.
In the Form editor Configuration panel, add or edit a description as desired. (In the source editor the description appears in the * @description line of the comments at the top of the editor.)
5.
a.
If you want to control the order in which rules execute, set the Priority field accordingly. Highest priority is 1. (In the source editor set priority = n where n is the priority number.)
If you want to also control the order in which rules with the same priority execute, set the Rank field accordingly. Browse to and select the rule function you created for this purpose. (If you want to use the source editor, add Rank=RuleFunction in the list of rule attributes.) See Using Priority and Rank to Control Order of Rule Execution for details.
6.
To disable forward rule chaining (the default behavior) uncheck the Forward Chain checkbox. (In the source editor set forwardChain = false.)
7.
In the Declarations panel (equivalent to the declare statements in the source editor), drag an ontology entity into the Declarations area, OR do the following:
a.
Click Add to add resources that you will be using in your rule. You see the Select Rule Declaration Arguments dialog.
b.
c.
In the lower half of the dialog, select a resource from the filtered ontology tree, and click OK. Your selection appears in the Declarations list. TIBCO BusinessEvents assigns an alias to the resource. You can edit the alias.
d.
To re-order the declarations, highlight a declaration and click the up or down arrow to move it. This is relevant only in rule functions, to order the arguments.
8.
In the Conditions panel (equivalent to the when statements in the source editor), write condition statements (in the TIBCO BusinessEvents rule language).
Each line is a complete statement. Each condition must evaluate to a Boolean value. Each line is joined to the others with an implicit AND operator. All of a rule’s conditions must evaluate to true for the conditions to be satisfied. See Order of Evaluation of Rule Conditions in TIBCO BusinessEvents Architect’s Guide for more information.
See Using Variables and Functions in the Rule Editor and Tips for Working in the Rule Editor for more information on working in the rule editor.
9.
In the Actions panel (equivalent to the then statements in the source editor), write action statements (in the TIBCO BusinessEvents rules language).
10.

Copyright © TIBCO Software Inc. All Rights Reserved