When you are copying data from a field in one system to another in Make, you are relying on that the field in the originating system always having data. But what if occasionally it’s empty? If it is empty, it can be handy to have a default value.

This is where Make’s ifempty() function comes in. This function allows you to set a default if the field you want to use is empty (has no data). If it is not empty, it will use the field data as normal.

The ifempty() function contains two parameters, the field and the default.

ifempty(field, default)

Field is the field you are mapping from the originating system (the one that triggers the scenario to run). If you weren’t using ifempty() at all, this is the field you could be using to map the data to the field in the target system.

Default is the value you want to use if the field is empty.

An example

For example, let’s say you have an optional country field in an event registration form. If someone registering for the event doesn’t fill in that field, you want to default it to your home country. I’ll use the United Kingdom for this example.

The event registration form is the trigger in the Make scenario for this example. When someone submits the form, the scenario will be triggered and will execute.

This is what the ifempty() looks like:

{{ifempty(11.data.country; "United Kingdom")}}

Let’s break down what this is doing.

The first parameter(11.data.country) is the country field from the event registration form.

The second parameter is the value you want to use if the first parameter is empty. This can either be a string, as it is here, or data from another field.

This is what it would look like if you are using the value from another field.

{{ifempty(11.data.country; 1.details.items[].registrationForm.country)}}

The first and second parameters are separated by a semicolon (;).

Nesting ifempty()

You can even nest the ifempty() function to check for multiple field values.

In this example, there is a new member application that triggers the Make scenario. I need to pass the membership level to another system (Airtable in this case). But the application form has a different field for the membership level for each region. I need to merge this into one field for the destination.

By nesting multiple ifempty() functions, I can check each one in turn. If it has data, then it will use it. If not, it will go to the next ifempty() and check if that field has data and use it if it has. And if that field also doesn’t have any data, it will go to the next region, and so on until it has been through all the regions to fine one with data.

{{ifempty(1.membership_level_england; ifempty(1.membership_level_singapore; ifempty(1.membership_level_uae; ifempty(1.membership_level_hong_kong; 1.membership_level_new_york))))}}

The final ifempty() is checking if there is data for Hong Kong. If there is, it will use it, and if there isn’t, it will default to New York. This ensures that ever region is checked. You could use a static value as the final else instead.

Wrapping up

Make’s ifempty is a quick and easy way to set default values for situations where you aren’t certain if the data will be available every time a scenario runs.

For more information on ifempty, check out Make’s official documentation on General functions

Similar Posts