Filter data by using routes and filters
There have been some repetitive questions in the community about how you can filter data that comes out of a module, so I will use this topic to combine some Q&A into a small tutorial.
Filtering data allows you to only do specific actions based on a rule you make. For example you can:
- Only continue if an item exists
- Only continue if some text contains a certain string
- Use multiple AND & OR logic to combine multiple statements
To start with this, you need to know what the following things are:
- Data types
Routes in Make are simply paths for data to flow within a scenario. Paths can be identified by the dotted line you will see between modules. You can also have multiple routes by using the “Router” module to act on data.
In Make, filters are used to narrow down data based on specific rules. You can see it as a funnel which has certain holes for specific data.
You can identify filters by the “Filter icon” you will see above a route. If you want to add or edit a filter for a specific route, you can click on the dotted line to open up the “Filter” settings.
In programming and also in Make, each item of data has a certain data type. You can have strings, objects, arrays, dates etc. which all has a their own set characteristics. More about data types is explained in thist post: Item data types explained.
How to use filters?
As explained above, filters can do all sorts of things depending on what your eventual goal is. You can stop scenarios, continue only with a specific set of data, and so on.
Filters can be set anywhere in the scenario, between modules you want to filter (you don’t need a router module). This means that if you set a filter all the way at the beginning of your scenario, it will filter the data you have at the beginning and only continue the remaining of the scenario with that data.
When creating a filter you have a whole list of operators to choose from for the expression you would like to make. You are basically creation if / else statements for your data.
When creating a filter, make sure you select the correct operator for your Data Type. If the data you are trying to filter doesn’t match the Data Type operator it might not work properly.
The most basic operators are the
- Does not exist
- Is equal to
These are used most of the time and are easy to understand.
The “exists” is basically checking if a certain value is present. If the data is present, it will continue the route and also run the remaining modules. If it’s not present it wil stop (for that specific item) and not continue the remaining modules.
2. Does not exist
The “Does not exist” is the same as the “exists” but the other way around. If the data is not present, it will continue the route and also run the remaining modules. If it is present it wil stop (for that specific item) and not continue the remaining modules.
3. Is equal to
The “equal to” operator is checking if a certain value exactly matches something you place in the filter. This can be usefull when you only want certain items with a specific value to continue.
Using AND & OR to narrow it down
Within filters, you can also use AND / OR operators to narrow down your data further.
When you are using the AND operator, the filter will only continue if ALL expressions within that AND are true. If one of the expressions is not true, it will not continue for that item.
When you are using the OR operator, the filter will check either one of the expressions within the OR rule. If either one of the expressions is true, it will continue for that item.
Creating a filter & running the filter
Once you have created the filter, you want to run the scenario and check the output of the expressions to make sure it’s working like expected.
You can click on the “Zoom” icon within the filter to check the output of it.
Using Router and Filters for specific actions
Now you understand the basics of filtering data between modules, you can also start using Routers to filter data and run specific modules with only that data.
When setting up a Router, you can create as many routes (or paths) as you like. Each route can have its own filter, and the data that matches that filter will only continue that route. This makes a Router excellent for doing specific actions for only a specific set of data items.
This is the filter for the IT department for example:
When eventually the data has checked all filters of a Router, but does not match anything you can also implement an else expression; this is called a fallback route.
The fallback route will be used for all data, which does not match any of the other routes. This way you can still do something with that data item.
Make sure you set the “fallback route” option to true for that specific route when you want to use this:
I hope all of the information above helps you getting started with filters and routes. Be creative and go do some testing when you get started with this.
If you require some assistance feel free to contact us or put down a comment below.