Introduction
This process creates a more complex rule that loops through a collection and uses a decision table to calculate a value for each collection member. You can test this rule by creating collection members and viewing each iteration.
Prerequisites
- The decision table must already exist.
- The constants must already exist.
|
Quick Steps |
| 1 |
Click the Create New Item icon, then select the Object Type |
| 2 |
Select the Rule Type |
| 3 |
Enter the logical rule details, then click Ok |
| 4 |
Declare the desired variables |
| 5 |
Add a Switch |
| 6 |
Add a ForEach loop |
| 7 |
Call the Decision Table and enter the parameter details |
| 8 |
Finish writing the rule logic in X# |
| 9 |
Add a Return |
| 10 |
Save the Rule, then compile the logical rule |
| 11 |
Open the Scenario, then open the Test Case |
| 12 |
Add a Collection, then add an item |
| 13 |
Enter the item details, then click Ok |
| 14 |
Enter the non-collection input values |
| 15 |
Enter the Expected Value for the return, then run the test |
| 16 |
View the result diagram |
| 17 |
Save the Scenario |
Detailed Steps
Step 1. Click the Create New Item icon, then select the Object Type.
This opens a dropdown list from which you can select an object to begin its item wizard. The item wizard creates a file or files.
The Object Type identifies the file the wizard will create. In this case, it is Rule.
Step 2. Select the Rule Type.
The Rule Type identifies the type of rule the wizard will create. In this case, it is Logical Rule.
Step 3. Enter the logical rule details, then click Ok.
The properties are:
- Entity: The rule is based on the entity. The fields available to the rule will be based on this entity's attributes.
- Name (ID): This is the rule's programmatic ID. This property is required. The ID must be unique, and it cannot start with numbers.
- Access Specifier: Specifies the level of accessibility of the rule.
- Return Type: This is the data type of the result you expect the rule to return (string, int, etc.).
- Is Collection: This is available when the logical rule returns a result. If checked, the rule can return a collection.
- Static: If checked, the rule will be available to call from anywhere. Otherwise, you will have to call it from an instance of its object. A logical rule can directly use the entity attributes if it is not static.
- Allow From Platform Api: If checked, the rule will be available from Platform API.
- Trace: Making a rule traceable means you can view the path and result every time the code executes that rule.
- Description: Optionally, you can enter a short description for your rule.
The Access Specifier options are:
Public: The rule is accessible from anywhere.
Private: The rule is accessible only from the current entity rules.
Protected: The rule is accessible only from this entity and any child entity.
The blank rule, is ready to be built.
Step 4. Declare the desired variables.
You can declare the variables by adding a code in X# which can later be used in your logical rule. Enter the below properties:
- Data Type: Type of data the variable uses (string, int, bool, etc.).
- Variable Name: String you are adding as a variable.
- Default: If the variable is local, you can assign it a default value.
Alternatively, you can also drag an element from the toolbox in Design mode. Refer Logical Rule Elements to get more details about Toolbox elements.
Step 5. Add a Switch.
Add a switch block in X# which has one if block and one else block, by default. It checks the order status for each order. If the order status is Ordered, it will calculate the discount. If the order status is any other value, it will set the discount to 0.
Step 6. Add a ForEach loop.
Now in X#, add a For Each loop inside the switch blocks. This is done by entering the Description, Item Name, and Collection. The Item Name is just a descriptive string you can use to refer to a member of the collection.
Step 7. Call the Decision Table and enter the parameter details.
Add a decision table inside the first For Each loop using the ID which is the name of the decision table you’re calling to calculate the discount.
In this example, if the Order Status is ORDR, the value of the offered discount is determined by the GetDiscount decision table. If the order status is not ORDR, the value of the offered discount is 0.
Enter the decision table details, its ID and parameters. These parameters are defined in the decision table. You need to pass their values to the logical rule definitions.
Step 8. Finish writing the rule logic in X#.
You have added a loop and decision table to the rule. Add the rest of the code blocks.
This rule uses two actions to calculate the net total value when the order status is ORDR and when it is not ORDR.
Add the action block inside the first Foreach loop by entering its description and expression.
Step 9. Add a Return.
The return value is the ldecNetTotal, the rule calculated in the previous actions.
This is how the logical rule flowchart appears when opened in Design mode.
Step 10. Save the Rule, then compile the logical rule.
Click the Save icon to save the rule.
You must compile the rule so it can be tested later.
Click the Compile Rule icon to compile the rule.
Step 11. Open the Scenario, then open the Test Case.
Click the Navigate to Scenario icon to open the scenario.
You can create a new test case or open the default one to test the rule.
Click the + icon to add a new test case.
Step 12. Add a Collection, then add an item.
Click the plus icon to add a collection for the loop to execute.
Click the Add Row button to add an item to the collection.
Step 13. Enter the item details, then click Ok.
Enter the value for an individual order.
Add as many items as you need for the test.
Step 14. Enter the non-collection input values.
This example's only non-collection input value is Orderstatus.
Step 15. Enter the Expected Value for the return, then run the test.
Enter the value you expect the rule to return based on the business logic.
Click the Run Test icon and select Current Rule to run the test steps.
Xelence provides the following options for running the test:
Only Result: Displays only the result.
Current Rule: Displays the result and diagram for this rule.
Child Rule: Displays the execution of any child rule.
Step 16. View the result diagram.
If you want to trace the executed logic, click the View Test Result icon to open the result diagram.
Double-click the loop icon to view the executed logic.
Step 17. Save the Scenario.
Close the diagram windows and save the scenario.
What are the improvements over S3 Version 6?
This is an identical process.
Related Articles
Create and Test a Logical Rule with One Condition
Use a Try Block in a Logical Rule and Test the Rule
Add a Variable to an Existing Decision Table and Test the Rule
Logical Rule Elements
This post is part of the Rules topic. Click here to open the Rules Overview.
#Xelence
#Rules