[Make Bot Questions] Most useful functions + examples of when and how to use them

:robot: Make Bot here bringing some of your FAQs to the community :robot: -

:question:

Heya Makers!

I understand that Make has this super powerful system of functions. Sounds pretty cool but I’m not sure how to use the functions so that I get the most value out of them.

Would you guys happen to have any insight into what the most useful functions are? And some real-life examples on how to use them on top of that?

2 Likes

Split a full name into first and last names:

Example: “First name” “Last name” (Full name)

First name:

{{get(split(1.name; space); 1)}}

Last name:

{{get(split(1.name; space); 2)}}

How it works:

a. This is a nested function that computes the split() function first. The split function takes the input string and outputs values based on the “where to split” argument; in this case, giving us a first name and last name value.

b. The get() function returns the value that you specify by the order; in our example, first name was split first, so using “1” will give us the first name and using “2” will give us the second name.

c. When mapping this into a field, we typically have either a “Full name” or “First name” and “Last name” separately; this gives us those separate names with a “Full name” input

9 Likes

Great start @datalytyks , to add up; it would look like this visually:

Screenshot 2022-02-16 at 09.31.23

Regex
But lets say you have a full name which doesn’t just have 2 sections and could be different each time. In the netherlands we have a lot of middle names such as mine: Bjorn van den Akker.

In this case the above won’t work, and it’s “better” to use something called RegEx. RegEx (or Regular Expressions) allows you to extract or replace text according to a certain pattern.
You can use the following regex to extract first name and last name from any kind of dynamic full name:

First:

(^\w+)

And last:

((?<=^\w+\s).+)

It would look like this:

Some more functions:

Creating a new array

If you want to make a new array with some items, you could use this.

{{add(emptyarray; "Item1"; "Item2"; "Item3")}}

Screenshot 2022-02-16 at 09.38.58

Creating an array out of a (CSV) string with seperators

Using the same split() function as above, this could help you turn a string with seperators (such as in a CSV into an array to iterate over them:

{{split("Bjorn, Jack, Dave, Admin"; ",")}}

Screenshot 2022-02-16 at 09.43.05

Okay done for now :wink:

7 Likes

Brilliantly put, @datalytyks! Thanks so much for sharing this with the community. This is eternally helpful information!

Thanks for jumping in with the visuals and the additional functions @Bjorn.drivn! I’ve heard stories about people struggling to work with names that consist of more than two parts so this is super valuable input.

One of the most useful functions in Make is “mapping”. Mapping is used to get data from the output of one module and use the data in the input of another module. Mapping sometimes involves filtering collections and arrays using a combination of functions: the get() and map() functions. There is an excellent write up on this which is a must read for anyone who wants to use Make effectively.

If you don’t want to read the article here’s a short preview:

Imagine you have a bundle of data that looks like this. You want to get the “no” value of the corresponding key in the array Meta data
image

This expression will obtain the value of the Value item of the element with key Meta data ID item value equal to 20642 :

image

Note that the get() function retrieves the first item in the returned array from map().

4 Likes

Ohh the good old get-map! I’ve heard countless stories about the convenience of this combo of functions!

1 Like

One of my favorite function in Make, if not my favorite is formatDate(). I have yet to find a date format that can’t be achieved with this function. Cool example:

image

Gives

image

The full list of tokens you can use to format your dates are here

2 Likes

Here’s a fun one that I was just asked by a client…

How do I run a scenario every other Thursday?

I had to give it some thought, but between the formatDate function that @loic.wiseflow discussed and a filter this can easily be done.

I started with a Compose String module and set the scheduling to run every Thursday:

Use the formatDate function to get the week number:

Then created 5 filters to allow even numbered weeks through:

  1. If week ends in 2 OR
  2. If week ends in 4 OR
  3. If week ends in 6 OR
  4. If week ends in 8 OR (not shown in screenshot)
  5. If week ends in 0 (not shown in screenshot)

6 Likes

Very clever @andyoneil ! Well done.

2 Likes

11 posts were split to a new topic: Filtering for aspect ratio

Can you explain your function expression further?

I recently had a case where I needed to strip through multiple layers of Arrays and Collections.
TL:DR, I used nested “map” and “flatten” functions.

My goal was to get a unique array of email addresses to iterate over.
My conerns were that the output from the trigger module would have hundreds of bundles, and I didn’t want to blow through a lot of operations.

Overview of this part of the scenario:

Sample output from the trigger module, with the email addresses I want coming in multiple bundles buried in an array of collections:

I used an aggregator on the value I wanted from the first module to process together all the bundles in 1 operation. You can see the input and output structures below. Again, the output has the email addresses buried deeply within arrays of collections, but at least now there is just one output bundle:


Screenshot (12)

The function that I used to strip this all apart is essentially just to roll back the different layers. First, it maps the array using the “attendees” to extract those as a separate array. Next, it flattens that down to make it a simple array, and finally it maps the email address field. For my own purposes, I also included a deduplicate function on the result, since I knew I would have lots of duplicates (for example, from our own staffmembers’ email addresses. You can see the function and the result below:
Screenshot (14)

One issue I ran into was that some meetings didn’t have an attendee array, and the functions would throw errors when they tried to map a null value. To get around this, I added a filter after the trigger to exclude those bundles, since I didn’t care about them.
Screenshot (11)

@alex.newpath does that explain it better? What do you think?

3 Likes

Great work. This will be useful for many others as this is a fairly common data manipulation.

1 Like