๐ค What Are Nested Conditions?
- Nested conditions allow you to ⛓️ embed multiple logical checks within a workflow, creating layered decision-making.
- They are useful for scenarios requiring sequential or dependent validations (e.g., tiered approvals, multi-criteria discounts).
๐ฐ Example: Tiered Discount Approval System
- Scenario: A company offers discounts to customers based on:
- ๐ง๐ค๐ง Customer Type (Regular or Premium).
- ๐ธ Order Value (above $500).
- ๐บ️ Region (eligible regions only).
- The flow must:
- ✅ Auto-approve discounts for Premium customers in eligible regions with orders >$500.
- ๐ง Escalate to a manager for Regular customers.
- ❌ Reject all others.
๐ช Step-by-Step Flow
1️⃣ Trigger
* "When an item is created or modified" (SharePoint list for orders).
2️⃣ First Condition: Check Customer Type
* **Expression:**
```
@equals(item()?['CustomerType'], 'Premium')
```
* ✅ Yes: Proceed to check region eligibility.
* ❌ No: Check if the customer is "Regular" (second condition in the No branch).
3️⃣ Nested Condition (Premium Customers): Validate Region
* **Expression:**
```
@contains(item()?['Region'], 'North America')
```
* ✅ Yes: Check if the order exceeds $500.
* ❌ No: Reject the discount (region ineligible).
4️⃣ Second Nested Condition: Check Order Value
* **Expression:**
```
@greater(item()?['OrderAmount'], 500)
```
* ✅ Yes: Auto-approve the discount.
* ❌ No: Reject the discount (order too small).
5️⃣ Handle Regular Customers (No Branch)
* **Condition:**
```
@equals(item()?['CustomerType'], 'Regular')
```
* ✅ Yes: Escalate to a manager for manual approval.
* ❌ No: Reject (invalid customer type).
๐บ️ Flow Structure Visualization
```
Trigger (New SharePoint Item)
├─── Condition 1: Is CustomerType = "Premium"?
│ ├─── Yes → Condition 2: Is Region = "North America"?
│ │ ├─── Yes → Condition 3: Is OrderAmount > $500?
│ │ │ ├─── Yes → Approve Discount
│ │ │ └─── No → Reject
│ │ └─── No → Reject
│ └─── No → Condition 4: Is CustomerType = "Regular"?
│ ├─── Yes → Escalate to Manager
│ └─── No → Reject
```
๐งฐ Key Expressions Used
- Customer Type Check:
@equals(item()?['CustomerType'], 'Premium')
- Region Validation:
@contains(item()?['Region'], 'North America')
- Order Value Check:
@greater(item()?['OrderAmount'], 500)
๐ Advanced Use Case
- Combine
AND
/OR
logic in a single condition:@or( and(equals(item()?['CustomerType'], 'Premium'), greater(item()?['OrderAmount'], 500)), equals(item()?['Region'], 'Europe') )
- Translation: Approve if the customer is Premium and the order is >$500, or if the region is Europe.
๐ก Best Practices
- ๐ Limit Nesting Depth: Avoid more than 3 layers to maintain readability.
- ๐ Use Switch Actions: For complex multi-branch logic, use the Switch action instead of nested conditions.
- ๐งช Test Incrementally: Validate each condition separately using Compose actions.
- ๐ฆ Leverage Variables: Store repeated values (e.g.,
item()?['OrderAmount']
) in variables for efficiency.
๐ Benefits of Nested Conditions
- ✅ Granular Control: Handle multi-step business rules (e.g., tiered discounts, approval chains).
- ๐ฏ Error Reduction: Validate all criteria before taking action.
- ๐ Scalability: Add new layers as business requirements evolve.
By mastering nested conditions, you can automate workflows with intricate decision trees, ensuring compliance and efficiency. Let me know if you’d like help designing a specific nested logic flow! ๐
No comments:
Post a Comment
Note: only a member of this blog may post a comment.