Power Automate Select vs Append to String

Power Automate Select vs Append to String

Introduction

I always look for the way of how to create fast and performant Flows. I was quite annoyed when each time when wanted to add a couple Users Emails from SharePoint Person field to notification or approval, I needed to use Append to String variable action in the For Each loop. In Power Automate Select vs Append to String I will show you the alternative way with Select & Join actions. Of course this technic can be used not only with Person field, but I will start with it.

Table of content:


Old method with loop and Append to String

Before explaining how to do it in a new way I feel that need to show the previous approach. My old way to extract Users Emails from SharePoint Person field (with option to add multiple Users enabled) was.

  • Adding new variable with Initialize variable action
  • Then Getting item references (in this case single item)
  • And next adding to Append to string variable action value of correct property from Dynamic content:

After performing such operation Power Automate adds to Flow Apply to each loop to iterate over every User added to field. Final touch was to add separator in the action Value property.

The result after Flow runs:

NOTE:
I used compose action only to show the string variable. Normally the next action would be Send email or Approval.

Why this is important?

As now with variable (left side) Send an email would be executed only ONCE and without it (string variable) for each User from Person field Flow would send email = executed action x number of Users. In many scenarios this is not desired behavior.

What more if Users Email property (right side) would be added to Approval action it would create a situation where Approval action is executed one after another for every User. For instance if 3 Users are added it would start Approval action for User 1 and wait for feedback, then start next Approval action for User 2 and so on. Again not desired behavior…

Long story short in many scenarios it is required to group/connect/concat/append values into one string.


New method with Select and Join

Instead, to use Append to String variable in loop I prefer to use Select and Join actions, result is the same, but performance is much better especially on bigger data sets.


High level explanation

I will keep on using SharePoint Person field with multiple User’s selection enabled as the example, but the method will work the same with Array or Get Items actions.

If you would like to see example with Array let me know in the comments.

First step is finding Select action in Data Operations group and adding it to the Flow, then:

  1. Select Object for From property
  2. Switch Map to text mode
  3. Add Email value to Map property

The second action required is Join action. To configure Join action I just need to find in Dynamic Content Output of the Select action and insert it to From property. Next in Join with property need to decided what will be my separator:

The result of the action will be a string of Emails separated by a chosen character. Output of Join action can be used in other actions like Send Email or Approvals.

For better understanding why to configure Select and Join in above way I decided to add also detailed explanation.


Detailed explanation

Select configuration

First step: Object

From property of Select action need to be populated with Object related to Person field.
The key is to find the correct property/Object it will be just the name of the field without any suffix like Display Name, Claims just the field Name (example on attached screen).

Second step: Map mode

Click Switch Map to text mode icon. Changing that setting is the heart of this method. If I used the key value mode:

The output of the Select action will look as follows:

Of course the output of Select action with the Key value mode enabled for some scenarios is very useful. For instance Create HTML table action (I will cover this topic in the next post).

If I would now combine that with the Join result does not meet my requirements to create a string of Emails:


Speed test

I couldn’t help myself and not to check how Flow will work with this method configured.

First test was for the three Users added to Person field and result was:

Not a huge difference 2 second slower is not that bad some will say.

Second test it was 100 items (Get items action):

29 seconds for 100 Items I think it is a huge gap in the speed.

I think I don’t need to look for more proofs that this method is way faster than working with the loop. It is also executing much less API calls which from licensing perspective is also important.


Summary

I really wanted to write Power Automate Select vs Append to String. As I like this method and for me the Flow configured in such a way is much easier to read, analyze and later on to maintain. As a bonus it is also next method how to remove the loop form your Flows, If you like to remove loops from your configurations check also Power Automate without loop.

I hope you will like this method and will start to use it in your Flows.

6 thoughts on “Power Automate Select vs Append to String

  1. When I use select data operation it will go array within array can you please help me in this?

    1. Hi Revati,
      It all depends on the data which you are using, check if you are using Get Item or Get Items as first is returning object and second array, so if you have People picker with option to select then you have first array of items and second array of Users selected.
      If this is not it, please provide more details.

      Regards
      Dawid

      1. I have 2 list first one is dynamic and second one is approver.
        In dynamic, One column is tech(choice type).
        In approver, one column is Title(tech value) and another column is approver(people or group type) having multiple approver. and I want to develop a dynamic approval flow.
        firstly I used Get items field and in which I enter filter Oquery : Title eq ‘Tech value from dynamic list’
        Then i used select data operation in which using from section i entered approver(from approver list) , this forced a apply to each loop which makes sense.
        When O go to map the Approvers email, it creates another apply to each. It goes array within the array.
        Please help as soon as possible.

Leave a Reply

Your email address will not be published. Required fields are marked *