Intermediate | Flow of the Week : Expressions for Non-Developers Part I
Hello Flow Fans!
Today’s post is written by Ed Gonzales; Community Super User and all around superstar!
As part of a series intended to help non-developers (like me) brave some of the intimidating aspects of Power Automate, I wanted to cover one of my favorite expressions in a very simple Flow…split().
Split is used to break up text string into an array, or a ‘table of substrings’ using a delimiter of your choosing. You can also use a zero-length (blank) string, which will result in each character being broken out individually.
In today’s example, we’ll use the function to extract the first and last name from an Email address which is formatted as firstname.lastname@email.com. We’ll use a manual trigger with a text input to get started, but you can insert this after any step passing your desired text string.
Click “Add an input” and select “Text”. Even though we are collecting an Email address, selecting “Email” will cause Flow to try to resolve the address to your specific tenant. Next, we’ll add a Compose action so we have a place to manipulate our string from the manual trigger. Click in the input field for the Compose, and then choose “Expression” to start building:
Looking at the sample input, Ed.Gonzales@email.com, we’ll want to first split on the ‘@’ which will give us two elements: “Ed.Gonzales” and “email.com”. Then, we can further parse the first element on the period, which will produce two more elements, “Ed” and “Gonzales”. With nested functions, I like to start in the middle and work my way out, so the first iteration will begin by typing “split(“ in the expression box, then clicking back to “Dynamic content” to select the input from the previous step. Add a comma and your delimiter (‘@’) in single quotes. It should end up looking like this:
split(triggerBody()[‘text’],’@’)
Flow assigns numbers to each element (beginning with zero), so if I only want the first element of the output array, I’ll add a [0] at the end like this:
split(triggerBody()[‘text’],’@’)[0]
This should result in an output that is only “Ed.Gonzales”. To further separate this part, I’ll add another split before the original, and then add a new comma at the end with ‘.’ as the second delimiter. The second iteration should look like this:
split(split(triggerBody()[‘text’],’@’)[0],’.’)
This should give two elements “Ed” and “Gonzales”. So now, it’s just a matter of assigning one element to a Compose for FirstName, and another for the LastName. Using my original Compose for FirstName, I just added the [0] at the end of the whole thing to only look at the first element. Also, to reduce complications later, I’ll convert everything from an array back to a string using the function of the same name:
string(split(split(triggerBody()[‘text’],’@’)[0],’.’)[0])
Copy that step and change the last element selection to [1] to grab the last name:
string(split(split(triggerBody()[‘text’],’@’)[0],’.’)[1])
The results should look something like this:
From there, you can add the data into whatever connector you’d like.
Play around with it, make mistakes, and learn along the way!
Try. Fail. Learn. Repeat.
Ed Gonzales has been working in technology for twenty-five years, covering many roles and developing new ones along the way.
His journey to bring customer relationship management (xRM) solutions to his current employer led to thought-leadership awards and recognition from leading industry experts and his peer community group.
Ever the polymath, his current endeavors include aviation science, aquaponics, and fostering orphaned kittens.
More information and his personal blog can be found at flyingpolymath.com and you can also connect with him on LinkedIn at /in/edgonzales.