When you're building workflows that process arrays or objects, you often need to narrow down your data. Maybe you only want high-severity alerts, or you need to exclude test accounts from a user list. Instead of manually picking through data, Tines gives you two functions that work like opposites: FILTER and REJECT.
What FILTER does
FILTER examines every item in an array or every key-value pair in an object and keeps only the items where your condition returns true. Everything else gets removed. Think of it like a security checkpoint: you define the criteria for what gets through, and FILTER only lets matching items pass.
FILTER basic syntax
Both functions take two arguments: The data you want to filter (an array or object) and the criteria for filtering (either a LAMBDA function or an array of values):
FILTER(array | object, values_to_keep | LAMBDA(arg1, [arg2], expr))FILTER example: Survey scores
Let's say you have a surveys array of survey responses and you only want the higher-scoring ones (higher than 7):
To only keep surveys with a score greater than 7, we utilize the FILTER function:
FILTER(action_name.surveys, LAMBDA(survey, survey.score > 7))action_name.surveys: The upstream reference path to the target surveys array.survey: Represents each individual item (iteration) in the surveys array asFILTERprocesses it.You declare this variable, so name it something that will help you and others better understand the overall formula.survey.score: The reference path to thescorevalue of thesurveyitem (iteration).
Translation: Go through each object within the surveys array, check the score value, and keep the entire object if its score value is greater than 7.
The output: Only the surveys that matched our condition were kept:
[
{"id": "S-001", "score": 9},
{"id": "S-003", "score": 8}
]What REJECT does
REJECT examines every item in an array or every key-value pair in an object and removes the items where your condition returns true. Everything else gets kept. Think of it like a blocklist: You define what should be removed, and REJECT filters those items out, keeping everything else.
REJECT basic syntax
Both functions take two arguments: The data you want to filter (an array or object) and the criteria for filtering (either a LAMBDA function or an array of values):
REJECT(array | object, values_to_remove | LAMBDA(arg1, [arg2], expr))REJECT example: Survey scores
Using the same survey score example, let's say you want to remove low-scoring surveys (score less than 5):
REJECT(action_name.surveys, LAMBDA(survey, survey.score < 5))action_name.surveys: The upstream reference path to the targetsurveysarray.survey: Represents each individual item in the surveys array asREJECTprocesses it.You declare this variable, so name it something that will help you and others better understand the overall formula.survey.score: The reference path to thescorevalue of thesurveyitem (iteration).
Translation: Go through each object within the surveys array, check the score value, and remove the entire object if its score value is less than 5.
The output: The low-scoring survey was removed, and everything else was kept:
[
{"id": "S-001", "score": 9},
{"id": "S-003", "score": 8}
]💡Note
Complex filter with multiple conditions
FILTER and REJECT can handle sophisticated logic using AND, OR, and nested conditions. Let's say you're processing this incidents array:
{
"incidents": [
{
"id": "INC-001",
"severity": "critical",
"status": "open",
"age_days": 5
},
{
"id": "INC-002",
"severity": "high",
"status": "open",
"age_days": 15
},
{
"id": "INC-003",
"severity": "medium",
"status": "closed",
"age_days": 30
},
{
"id": "INC-004",
"severity": "critical",
"status": "open",
"age_days": 2
},
{
"id": "INC-005",
"severity": "low",
"status": "open",
"age_days": 60
}
]
}We want to keep incidents that need immediate attention, so let's identify the criteria we need to check:
Critical OR high severity AND
Open AND
Older than 3 days
To only keep the incidents that match these conditions, let's use this FILTER formula:
FILTER(
action_name.incidents,
LAMBDA(incident,
AND(
OR(incident.severity = "critical", incident.severity = "high"),
incident.status = "open",
incident.age_days > 3
)
)
)Translation: Go through each object within the incidents array and check the following: Its severity is high or critical, its status is open, and its age_days is greater than 3. Only keep the objects where all conditions are met.
The output: Only the incidents that matched the multiple conditions were kept:
[
{"id": "INC-001", "severity": "critical", "status": "open", "age_days": 5},
{"id": "INC-002", "severity": "high", "status": "open", "age_days": 15}
]Combine with other functions
Both FILTER and REJECT work well in nests and chains with other functions. Let's look at this students array:
{
"students": [
{
"id": "L-01",
"first_name": "Priya",
"last_name": "Desmond",
"status": "active"
},
{
"id": "L-02",
"first_name": "Maya",
"last_name": "Brennan",
"status": "active"
},
{
"id": "L-03",
"first_name": "Jordan",
"last_name": "Kim",
"status": "inactive"
},
{
"id": "L-04",
"first_name": "Lucas",
"last_name": "Ortega",
"status": "active"
}
]
}We want to:
Only keep active students.
Sort them by last name.
How do we do this? By combining FILTER and SORT together, either by nesting:
SORT(FILTER(action_name.students, LAMBDA(student, student.status = "active")), "last_name")or, by chaining:
FILTER(action_name.students, LAMBDA(student, student.status = "active")) |> SORT(%, "last_name")We can get the results to look the way we need:
[
{
"id": "L-02",
"first_name": "Maya",
"last_name": "Brennan",
"status": "active"
},
{
"id": "L-01",
"first_name": "Priya",
"last_name": "Desmond",
"status": "active"
},
{
"id": "L-04",
"first_name": "Lucas",
"last_name": "Ortega",
"status": "active"
}
]