FlexiRule Docs
Recipe: Work with Child Tables and Item Calculations
Learn how to visually iterate over child table items, evaluate row attributes using the Smart Value Selector, and calculate discounts.
Recipe: Work with Child Tables and Item Calculations#
Child tables (such as Sales Order Items, Purchase Invoice Items, or Quotation Items) contain multi-row details. Automating line item calculations requires looping through rows and applying transformations visually.
In this recipe, you will build a rule that iterates through Sales Order Items, checks line item properties, and applies discounts.
Scenario Overview#
Business Goal: Apply a 10% promotional discount to all line items belonging to the "Electronics" item group in a Sales Order before saving.
- Target DocType:
Sales Order - Trigger Event:
DocType Event->Before Save - Visual Nodes:
Start->Repeat (Loop)->Check->Set Value
Step-by-Step UI Instructions#
Step 1: Create the Rule#
- Navigate to FlexiRule -> Rule List -> New.
- Set Rule Name to
SO - Electronics Item Discount. - Set Document Type to
Sales Order. - Set Trigger Event to
Before Save. - Click Save and open the Rule Builder.
Step 2: Add and Configure the Repeat (Loop) Node#
- Connect a Repeat (Loop) node from the Start node’s outbound port.
- In the Repeat configuration panel:
- Click the Collection Source field and type
@to open the Smart Value Selector. - Search for
Itemsand select Sales Order → Items (Child Table). - Set Item Alias to
item(this creates a temporary loop variable for the active row).
- Click the Collection Source field and type
Step 3: Add Check Node Inside the Loop Body#
- From the Loop (True/Body) outbound port of the Repeat node, connect a Check node.
- In the Check configuration panel:
- Click the left value field and type
@to open the Smart Value Selector. - Navigate to Loop Context (item) and select item → Item Group.
- Set the Operator dropdown to Equals.
- In the right value field, enter
Electronics.
- Click the left value field and type
Step 4: Calculate Line Discount using Set Value#
- From the True outbound port of the Check node, connect a Set Value node.
- In the Set Value configuration panel:
- Click Add Assignment.
- Click the Target Path field, type
@, navigate to Loop Context (item), and select item → Discount Percentage. - Set Operator to
Set. - In the Value field, enter
10.
- Drag a connection from the outbound port of the Set Value node back to the Repeat node to continue the loop for remaining items.
Step 5: Test and Save#
- Click Test Run in the action bar and select a Sales Order containing Electronics items.
- Click Run Test and observe the visual execution path looping through line items.
- Enable the rule and save.
Key Takeaways#
- Loop Connections: Always connect the final node in a loop body back to the Repeat node to continue processing remaining rows.
- Loop Variables: Use the Smart Value Selector to pick fields on the current loop row under Loop Context (
) .
Was this page helpful?