web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Adding strings to emai...
Power Automate
Answered

Adding strings to email depending on SharePoint value

(0) ShareShare
ReportReport
Posted on by 52

I have a flow that sends an email when a new SharePoint item it added. What is the best way to insert strings (I'm assuming variables) depending on the value of a SharePoint field?

 

For instance, if the value from the SharePoint field is 555 - Orlando, FL, I want to detect the Orlando, FL portion and then insert a phone number and email address for that location (this information is not contained in SharePoint and I cannot change the SharePoint to add this). So I'm assuming I would set the phone number and email address as variables but not sure where to store the information. Thanks.

Categories:
I have the same question (0)
  • rzaneti Profile Picture
    4,241 Super User 2025 Season 2 on at

    Hi @doug_tn ,

     

    Will you have several locations or only a few? If you have a few, you can manage it inside Power Automate without bigger problems. If you have a large quantity, you still can use only Power Automate for that, but I would recommend you to store it into another SharePoint List, or at least into an Excel table - it will make easier to identify errors in the future or to update the contact info, if needed.

     

    In any case, your flow will basically

    - Capture the data from SharePoint List field

    - Compare it to a set of records to find the correct contact info for the location (as mentioned before, these records can be stored into a Power Automate variable or in an external source)

    - Eventually, these contact info pulled from the records will be assigned to variables and

    - It will populate your email template.

     

    If you need any help to build a flow like this, let me know and I provide you with a step-by-step (just clarify if you will keep the contact info into Power Automate variables or in external sources). 

  • doug_tn Profile Picture
    52 on at

    Thanks @rzaneti... step-by-step would be appreciated. There would be roughly 100 facilities so external source would be the way to go. I didn't think about using another SharePoint site to store the data... that sounds awesome.

     

    I generally understand I can connect to the other SharePoint and pull the data but not clear on the "if location = 555 - Orlando, FL", use these values. Thanks.

  • Verified answer
    rzaneti Profile Picture
    4,241 Super User 2025 Season 2 on at

    Hi @doug_tn ,

     

    Here is your step-by-step and the answer to match location with Orlando, FL 🙂

     

    If the steps below are not clear enough or if your process is a little different from the example, let me know and we work together to make the necessary changes. 

     

    Lists overview

    We are working with a 'customers list', from where we will extract the 'office' data to find the contact info:

    rzaneti_0-1693599269270.png

     

    The contact info is stored in this other list:

    rzaneti_1-1693599326187.png

     

    As you can see, the customers list contains a kind of numeric code before the city name ("xxx -"), while the office list has only the city name. I'm assuming that all of your 'customer' records will follow this pattern: if this is not the case, we may need some small changes in the flow design. 

     

    Step 1 - Create the trigger and extract the office city

    First, add a 'When an item is created' trigger and populate it with your List details. After that, initialize a string variable to store the office city:

    rzaneti_2-1693599567677.png

     

    In the 'Value' input, we are setting an expression that will access the content from the 'office' field of the new record added to your list, but extracting only the text allocated after the "-". The expression is the following: 

    trim(split(triggerOutputs()?['body/Office']'-')[1]). Here is a quick explanation about each element of this expression:
    • triggerOutputs()?['body/Office']: this is the dynamic content related to your 'Office' column from the customer list. You don't actually need to type it, but just add it as dynamic content. To add a dynamic content inside an expression, add some text to you 'Fx' input (highlighted in yellow), keep the cursor focused into the input and then navigate back to the 'dynamic content' tab (highlighted in green) to select the desired content highlighted in blue):

    rzaneti_3-1693599873818.png

     

    • '-': this is the separator that we are using to isolate only the last part of '555 - Orlando, FL'
    • split: this is the expression that actually will return to us 'Orlando, FL', from '555 - Orlando, FL'. We are passing two parameters to it: the text to split (triggerOutputs()?['body/Office']) and the separator to define where the text must be broken ('-'). This expression will return an array, which will look like this: ['555 ', ' Orlando, FL']
    • [1]: as mentioned before, the split will return an array, and we need to access its second element (Orlando, FL). To access elements from arrays into expressions, you need to pass it index between brackets, and as Power Automate arrays are zero-indexed (the counting starts at zero), the second element will be [1].
    • trim: as we have a blank space between '-' and 'Orlando', the final result of the expression until now will be ' Orlando, FL' (with an extra blank space at the beginning). If we compare it to the value existent in the office list, we won't find any result, as this extra blank space make the both strings different. So we use the trim expression to remove any blanks from the beginning of from the end of the text.   

     

    If you are new to build expressions or to include dynamic contents into them, refer to this article that I recently wrote about it (and, of course, ask here if you need additional clarification): http://digitalmill.net/2023/07/31/using-dynamic-content-in-power-automate/ 

     

    Also, there is this other article about text expressions that brings some instructions about split, trim and array indexing: http://digitalmill.net/2023/08/12/how-to-extract-and-clean-texts-with-power-automate/ 

     

    Step 2 - Return the office contact info

    Now we need to find the contact info among the records into our office list. We can achieve it by adding a 'Get items' action and including a filter query to restrict the retrieved records to only those which office city (in my List, the 'Title' property) matches to our 'office' variable:

    rzaneti_4-1693600719427.png

     

    You just need to populate your 'Get items' action with the details from your office list and, into the filter query (highlighted in yellow), write Title eq '[VARIABLE_DYNAMIC_CONTENT]'. Make sure to change 'Title' for the column name that is storing your office location. Also, make sure to surround the dynamic content from 'office' variable with single quotes (otherwise, you will receive an error).

     

    It will return an array containing a single record (unless you have more than one record for the same city). 

     

    Step 3 - Populate your email

    For this step, I will use a Microsoft Teams message step, but you can use the same logic for an Outlook email one 🙂

     

    Just insert your email action and populate it with the dynamic content extracted from 'Get items' action. Once you include a first dynamic content, it automatically will generate an 'Apply to each' action. Don't worry: as the 'Get items' output is an array, this is the expected behavior from Power Automate, and as it has only one record, the 'Apply to each' won't result in dozens of repeated messages:

    rzaneti_5-1693601248272.png

     

     

    Output

    Let's test the flow! I included this new record:

    rzaneti_6-1693601282593.png

     

    The flow ran successfully:

    rzaneti_7-1693601300484.png

     

    And I received the Teams message (only one) with the content populated from the office list:

    rzaneti_8-1693601348583.png

     

    Let me know if it works for you or if you need any additional help!

     

    -------------------------------------------------------------------------
    If this is the answer for your question, please mark the post as Solved.
    If this answer helps you in any way, please give it a like.

    http://digitalmill.net/ 

    LinkedIn

  • doug_tn Profile Picture
    52 on at

    @rzaneti this is amazing... I greatly appreciate your assistance and the outstanding explanation. I will play around with it this weekend and report back. Thanks again.

  • doug_tn Profile Picture
    52 on at

    Thank you @rzaneti... works great and I learned so much.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard