🤖 What are the most useful functions in Make and some examples of using 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

11 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:

9 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().

You may be asking why the second and third argument are value and id where the actual display is Meta data ID and Value. This is because the raw names of each of these keys is different than the display name. Hover over each element in the mapping “star” panel and see what the raw name is. This is what you should use in the map() parameters. Do not click on these to map them as it will not work. This is a common mistake.

5 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

3 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)

9 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?

4 Likes

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

3 Likes

Hi all,
Jumping one year into the future :slight_smile:
We’ve got an API that is responding with a very awkward data structure. The structure cannot be changed by the API provider, so we have to manipulate it. The biggest problem is that the API is sending all values as arrays. This is creating challenges when trying to do basic tasks with this data, For example, filter “exist” will always return true (even if array is empty), length will return wrong values, etc. Another strange thing is that Make sees some of the empty arrays as "\r\n ".
Any ideas on how to elegantly manipulate this into a more workable data structure?
Here’s the response from the API:


You can see that it’s a collection of arrays.

I’ve attached a neutralized example below.
Thanks!

{
  "LeadID": [
    999
  ],
  "CampaignID": [
    9999
  ],
  "Source": [
    "site"
  ],
  "Name": [
    "\r\n      "
  ],
  "Phone": [
    "9999"
  ],
  "Email": [
    "\r\n      "
  ],
  "Status": [
    "\r\n      "
  ],
  "Remarks": [
    "{\"Age\":\"\",\"Language\":\"\",\"Branch\":\"\",\"Question1\":\"\",\"Question2\":\"\",\"Question3\":\"\",\"Question4\":\"\",\"Question5\":\"\",\"UserFreestyleInput\":\"\",\"UserFreestyleTranslated\":\"\",\"DetectedLanguage\":\"\"}"
  ],
  "Agent": [
    "\r\n      "
  ],
  "Marketing": [
    false
  ],
  "InsertDate": [
    "2/20/2023 2:02:42 PM"
  ],
  "CallStatus": [
    "\r\n      "
  ],
  "CallID": [
    "0"
  ],
  "Link": [
    "https://www.999.com/"
  ],
  "MoreDetails": [
    "\r\n      "
  ],
  "RecordLink": [
    "\r\n      "
  ],
  "GeneralSource": [
    "\r\n      "
  ],
  "IPAddress": [
    "9.9.9.9"
  ],
  "FormName": [
    "\r\n      "
  ],
  "CampaignName": [
    "999"
  ]
}

This is pretty common actually @LH . All APIs respond with Arrays and collections within the arrays – it’s just in your case it is nested a bit more than usual.

You will want to read about the map() function and using get() to extract what you need from it (or the new first() function). Start here and experiment so you understand exactly what you need to do.

As for the data in the values of the collections you can manage those with the text functions and trim out the white space if necessary. You’re just going to have to deal with what you are given and Make will help you do that.

I suggest heavily with starting with simple API responses with less data not to overwhelm you when playing with the setvaribable module and extracting data from the output bundles.

3 Likes

This is huge. Thank you!! I have run up against this trouble often when I deal with linkedPulseIds in Monday.com, and have oscillated between doing costly operations to grab the data to awkward work arounds that make life more complicated…and now this!! In one simply operation!! Thank you, thank you, thank you. Stumbled on it with the search of “Deeply Nested”. I think this post should be required reading for everyone starting with Make. the get(map()) works for some things, but the flatten is key and very helpful.

2 Likes

Needed to ask Bing how your second bit of regex worked. It was very helpful:

This is a regular expression that uses a positive lookbehind (?<=...) to match one or more characters .+ that come after a word \w+ followed by a space \s at the beginning of the line ^. In other words, it matches everything after the first word in a line.

2 Likes

What is the most useful function in Make?

The one that solves the problem in front of you at the moment :grin:

Too many good ones to list here!

1 Like