Power Automate Substring and Text Positions Made Easy

Expressions can be confusing when starting out in Power Automate. Luckily the product team makes things easier each day. I will be showing how to grab an email address Josh.Cook@flowaltdelete.ca and transforming it to Josh Cook

Expressions can be confusing when starting out in Power Automate. Luckily the product team makes things easier each day. I will be showing how to grab an email address Josh.Cook@flowaltdelete.ca and transforming it to Josh Cook

The Scenario

For this demo, we will be formatting an email address and removing everything after the ‘@‘ symbol, to form a first name and last name.

We will be using Substring to achieve this. However we wont be using the expression Substring, we will be using a Action called Substring, this action can be found in the ‘Text Functions‘ connector.

The Flow

In my Flow I will use a Compose action to store an email address, this can be any data source or action that fits your needs.

In this example, we want to remove the At sign and everything after. To do this we could use an expression. But.. The Power Automate team has put together some actions that make Text Functions more easy.

At this time there is Two(2) Text Function action we can utilize.
1. Find text position
2. Substring
We will you both in this example

First we will add the ‘Find text position‘ action. This action has Two(2) parameters to fill in:
Text – The text we want to use, in this case we use the dynamic content of our Compose with the email
Search text – This is the text we want to find the position of

In the string Josh.Cook@flowaltdelete.ca the ‘@’ sign is in position 9. This is because in indexing values we count the first value as index 0

Next we add the ‘Substring‘ action. This action has three(3) parameters.
1. Text – The string of text to extract the substring from
2. Starting position – since we want to extract ‘Josh.Cook‘ our position will be 0
3. Length – This is how long the substring will be, so this is where we use the dynamic value from Text Position action (Which is 9)

Now when we run the Flow, we should take the value:
Josh.Cook@flowaltdelete.ca‘ And output ‘Josh.Cook

Mhm.. Not bad, now all that is needed is getting rid of the ‘.’ This can easily be done by using the replace() expression.
replace(<Dynamic Substring Body>,’.’,’ ‘)
The replace expression is replacing the ‘.’ with a white space char

replace(outputs('Substring')?['body'],'.',' ')

Now when we run the flow:

Conclusion

These new Text Function actions in Power Automate makes expressions even easier. I cannot wait to see what the Product group adds to these.
Thanks for reading, and as always please reach out to me on Twitter with any questions you may have. Thanks again!

Power Automate – Format Phone Number Easy

Take a phone number like 4031234567 and turn it to (403)-123-4567 with one simple step!

Take a phone number like 4031234567 and turn it to (403)-123-4567 with one simple step!

Scenario

We have a phone number coming in from a secondary system as a integer number. We than want to add some formatting to this to be easily read and look cleaner. For example, a phone number comes in like this:
4035557890 And make it look like (403)-555-7890

Things to Know

Since we add ‘-‘ and ‘( )’ this turns our data type to become an String. Keep this in mind, since you wont be able to pass this into a field in another system that is looking for a Integer value

The Flow

This Flow is very simple. To achieve the formatted number I am using the action ‘Format number’. This is a fairly new connector that is mainly used to format currency values. But we can utilize the format to define any formatting we want

Looking at the above picture, we are passing a Integer phone number into the Format number action. Than we specify the format we want to use by selecting the drop down > clicking ‘Enter custom value

End Result!

Conclusion

Since this action is fairly new, I am curious and looking forward to see if the Power Automate team will expand and add more actions like this to make formatting a breeze.

Thanks for reading!