Blog Viewer

Create and Test a Logical Rule with a Loop and Call to Decision Table

  

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. 

QUICK STEPS
1 Open the entity
2 Open the Rules section in the Home tab and create a new logical rule
3 Enter the details
4 Click OK
5 Drag a for loop to the field
6 Enter the description, item name, and collection
7 Drag the switch under, and inside, the for loop
8 Enter the descriptions and expressions
9 Drag the decision table to the right of the if block
10 Enter the description and ID
11 Enter the parameter expressions
12 Finish designing the rule
13 Drag a return at the end of the for loop
14 Enter the description and expression
15 Click the Variables icon to add a variable
16 Enter the details
17 Click OK
18 Add the rest of the variables
19 Save the rule
20 Build the entity rule
21 Add an entity scenario
22 Add a collection
23 Enter any number of items
24 Close the item list
25 Enter the non-collection input values
26 Click the + icon below Expected Value in the Output table
27 Enter the Index and Expected values
28 Enter the Expected Value for the return
29 Run the test
30 View the diagram
31 View the loop
32 View the call to the decision table
33 Save the scenario


Detailed Steps

Step 1. Open the entity.

Open the entity you want to create the rule on.

Before you begin, make sure all the prerequisite files and relationships for the rule are in place. The rule for this example needs the following:

  • An Account entity.
  • Account attributes for the rule (AccountType, NoOfMonths, OpeningAmount, and InterestRate).
  • A Customer entity. 
  • Customer attributes for the rule (FirstName, LastName, and CustomerType).
  • A relationship between Customer and Accounts to create a CustomerAccounts collection.

 

 

Step 2. Open the Rules section in the Home tab and create a new Logical Rule.





    Step 3. Enter the details.

    The rule is not static because you're going to need to use the attributes and relationship you created earlier. It returns a decimal.





    Step 4. Click OK.

    S3 creates the rule. It is ready for you to build.




    Step 5. Drag a for loop in the field.





    Step 6. Enter 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, which comes from the one to many relationship you created earlier.



      Step 7. Drag a switch under, and inside, the loop.



      Step 8. Enter the descriptions and expressions.

      This switch checks the account type for each customer account. If the account is a CD account, it will calculate interest (you’ll configure that next). If the account is any other type, it will set interest to 0 (you’ll configure that a little later, too). To refer to the account type, the switch calls the AccountType attribute from the Accounts entity via the collection in the Customer entity.




        Step 9. Drag the decision table to the right of the if block.




        Step 10. Enter the Description and ID.

        The ID is the name of the decision table you’re calling to calculate each account’s interest. The decision table must already exist. This example uses the GetInterestRate_01 decision table. 




        Step 11. Enter the parameter expressions.

        These parameters are defined in the decision table. You need to pass their values to the logical rule definitions. 



        Step 12. Finish designing the rule.

        You have added a loop and decision table to the rule. Add the rest of the elements.

        This rule uses actions to assign 0 interest if the Account Type is Checking, or to calculate interest if the Account Type is CD.


         

        Step 13. Drag a return at the end of the for loop.


        Step 14. Enter the description and expression.

        The return value is the idecTotalAccountValue the rule calculated in the previous action. 



        Step 15. Click the Variables icon to add a variable.

        You need to define a local variable for Interest Rate.



        Step 16. Enter the details.

        Enter the ID and data type of the Variable.




        Step 17. Click OK.



        Step 18. Add the rest of the variables.

          You need to define decimal local variables for InterestAmount, MaturityValue, and TotalAccountValue.




          Step 19. Save the rule.

          Click the Save icon.



          Step 20. Build the entity rule.
           




          Step 21. Add an entity scenario.

          In scenarios, click the Add Scenario icon.




          Step 22. Add a collection.

          The parameters you need to enter are defined for each member of the collection, so you have to enter the values individually for each account the customer has.

          Click the plus icon to add a collection for the loop to execute.




          Step 23. Enter any number of items.

          Enter the accounts. This example uses two accounts: one CD and one checking account.





            Step 24. Close the item list.




            Step 25. Enter the non-collection input values.





            Step 26. Click the + icon below Expected Value in the Output table.






            Step 27.
            Enter the Index and Expected values.




            Step 28. Enter the Expected Value for the return.





              Step 29. Run the test.



              Step 30. View the diagram.

              The diagram shows the logic the rule performs:

                      1. Execute the loop for each customer account.

                      2. Return the total account value.




              Step 31. View the loop.

              Double click the loop icon to view the executed logic for each amount.

                      1. Check the account type.
                                  a. If the account type is CD, calculate the interest rate.
                                  b. Else, set the interest rate to 0.

                      2. Calculate the interest amount, then add to the running total and opening amount.




              Step 32. View the call to the decision table.

              In the loop, double click the decision table icon to view the executed logic for determining the interest rate. In this case, the customer is PREM and the duration is between 48 and 59 months. Therefore, the rate is 1.75.

               

               

              Step 33. Save the scenario.

              Close all the diagram windows and save the scenario.

               
              This post is part of the Rules topic. Click here to open the Rules Overview.

              #Develop
              #Rules
              #Text Help
              #Everyone
              #Task Steps

              0 comments
              39 views

              Permalink