Configure the InitializeAccount Rule FunctionIn this task, you configure a rule function that you will later set to execute at startup. The InitializeAccount rule function sets values for the FraudCriteria scorecard properties. It also creates an instance of the Account concept.What is a rule function? A rule function is a function you write in the BusinessEvents rule language.How are rule functions created and used? You write rule functions using the rule editor. You can use rule functions in rules and other rule functions, in event preprocessors, and as startup or shutdown functions for an agent.What is an ontology function? An ontology function is automatically created for each concept and event in your project. These are constructor functions. Another type of ontology function enables you to create and schedule a time event.What other types of functions are there? BusinessEvents provides a large library of functions. You can also add custom Java functions. See Chapter 4, Creating Custom Functions in TIBCO BusinessEvents Language Reference for details.
1. At the project level, create a Rules folder.
2. Open the Rules folder, right-click in the design panel, and select Add Resource > BusinessEvents Workbench > RuleFunction.
3.
4. In the design panel, double-click InitializeAccounts to open it.
5. Add the following lines to provide values to the FraudCriteria scorecard (and to comment your code):
FraudCriteria.interval = 120*1000; /* 120 seconds */
Notice that when you type the period after FraudCriteria, a list of its properties pops up so you can select a property.
6. On the right side of the user interface, click the vertical Ontology tab and expand the list under Ontology Functions. You can make the function area larger to see the list more easily. You see the same folder structure as you used to build the ontology.
7.
8. Drag the ontology function corresponding to the Account concept onto the design panel. The following signature is provided for you:
Concepts.Account.Account(/*extId String */,/*Balance double */,/*Debits double */,/*Status String */,/*AvgMonthlyBalance double */)
10. Now enter the following. Notice again, that when you type the period after System you can select debugOut from a list. The hash marks, by the way, are just to make the message more visible when printed to the console.
System.debugOut(""###############Created account ActA ###############");
11. Click Apply, then save the project.Another way to create an instance of a concept is to use a standard function called Instance.createInstance(). If you want to learn about this feature, complete this exercise to create a second instance of the Account concept.
1. Put the cursor on a new line in the rule editor and click the vertical Standard tab (on the right side of the TIBCO Designer window) to view the library of standard functions.
2. Expand the list so you can see Instance.createInstance().Note that the function name has a small "m" to the left of the "f" icon. The "m" indicates a mapper function.
3. Drag the createInstance function to the design panel and type an open parenthesis at the end of the name. A link to the XSLT mapper appears:
5. First you’ll select the type of concept you want to create an instance of. In the Entity Path field of the Function tab, browse to and select the concept Account, then click Apply.
6. Click the Input tab to see the Scope Variables and Function panels. Expand the tree in the Function panel and enter values for ActB. Except for the account ID (@extId), you can use the same values you entered for ActA. Your display looks like this:You can also use global variables to set initial values at runtime. To use a global variable, you expand the Scope Variables panel and drag the cursor from the variable name to the property or attribute name.
7. Click Apply then click OK to dismiss the window. Close the parentheses and end the line with a semicolon. The finished line looks like this in the rule editor (with additional colors and formatting):
Summary and Next StepsYou have configured a rule function that will initialize an account (optionally two accounts) at runtime. Next you will configure rules that take action on arrival of debits, depending on whether the fraud criteria are met or not.
Copyright © TIBCO Software Inc. All Rights Reserved.