Ask AI
Skip to main content

Filter by a condition

Function: Filter by a condition

This action helps you narrow down a list of items based on specific criteria you define. Imagine you have a long list of customers, products, or tasks, and you only want to see the ones that meet certain conditions, like customers in a specific region or products below a certain price. This action allows you to do just that, creating a new, smaller list containing only the items that match your rules.

Input,

  • List to Filter (LIST, Array of Objects, Required): This is the original list of items you want to sort through. For example, a list of all your products, or all your employees.
  • Condition (CONDITION, String, Required): This is the rule that each item in your list must follow to be included in the new, filtered list. You'll write this as a simple expression, like item.price < 50 to find products cheaper than 50, or item.status == "Active" to find active users.
  • Attribute to Filter By (LIST_OBJECT_ATTRIBUTE, String, Optional): If your condition is very simple and only checks one specific part of each item (like price or status), you can optionally specify that attribute here. However, it's often easier to include the attribute directly in your Condition (e.g., item.price).

Output,

  • Result (RESULT, Number): A number representing the list that has been filtered based on your condition. This number could be a count of the items that met the condition, or a reference to the newly created filtered list.

Execution Flow,

Real-Life Examples,

  1. Finding Overdue Tasks

    • Inputs:
      • List to Filter: A list of all tasks in your project management system.
      • Condition: item.dueDate < today\(\) (assuming today\(\) is a function that returns the current date)
      • Attribute to Filter By: (Leave blank, as the condition directly uses item.dueDate)
    • Result: A number, for example, 5, indicating that 5 tasks are overdue.
  2. Identifying High-Value Customers

    • Inputs:
      • List to Filter: A list of all your customers.
      • Condition: item.totalPurchases > 1000
      • Attribute to Filter By: (Leave blank)
    • Result: A number, for example, 15, representing the 15 customers who have made over $1000 in purchases.
  3. Filtering Available Products by Stock Level

    • Inputs:
      • List to Filter: A list of all products in your inventory.
      • Condition: item.stockQuantity > 0
      • Attribute to Filter By: (Leave blank)
    • Result: A number, for example, 120, indicating that 120 products currently have stock available.