Frequently, the need arises to check if information in a flow has a certain value. Depending on how structured the information being returned from an API is, there are several different ways to solve for this using FQL.
contains is the most straightforward way to check if some quoted information has a word or pattern (regex). Since contains
returns either true or false, it's often used with an If block. The example below illustrates how information is only passed through the If block when the input has the expected value.
Use filter to get a subset of elements from a larger list of elements. To use filter
, the function looks like $filter(list name,fn($v,$i,$a) { filter condition })
where $v
is the values in the list, $i
is the index (zeroth item, first item, second item, third item), and $a
is the entire list. $v
is typically the important value for filtering and the only one actually required to be used. In the example below, there is a list of companies, but only enabled companies are needed for the remainder of the flow.
count returns the number of items in a list. This is commonly used because APIs often return lists of items when the flow is looking for one particular item. When this happens, the flow needs to check if only a single record is returned by the API or if there is a list and further filtering is required. Another case where this function is useful is in generating a random result from a list. In the below example, the recipe API returns a list of recipes and the flow selects a random one from the list.
distinct returns only the unique items in a list. Sometimes, there are duplicate entries in a list of results (maybe someone signed up with two different emails) and the flow needs to filter them out.
Last modified: 2024/06/04