cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Lumenia
New Member

Posting random person's name to Teams

Hello,

 

I have a SharePoint list and want to build a flow that would randomly pick a person from the list and post it to Teams channel. Something like "Hello @ ABC you have been selected!".

The person can be picked only once.

 

I try to replace the person's name with outputs('Compose') but I get blank messages on Teams instead of the name.

 

I'd be grateful for help!

2 ACCEPTED SOLUTIONS

Accepted Solutions

 Since you've indicated that you want to only post the name once, you will need a way to filter out the names that have already been posted. Add a column to your SharePoint list to store a value. For my SP list, I'll use a Date and Time Column. 

 

Get Items

In the Get Items action, you'll need to specify a filter query. You will need to use the internal column name of your column. Keep in mind that the internal column name may not always match the name displayed in your Sharepoint list. If you aren’t sure how to get this, please refer to this section of one of my YT tutorials.

 

Use the eq (equals to) operator and enter null. This filter query will return items where the Posted on Teams (in my case) Column doesn't contain a value.

 

Specify a Top Count (optional)

Depending on how many items you have in your SP List, I would recommend limiting the Top Count to a smaller number than the total number of items in your list. This will increase the speed of your flow runs. Instead of returning all items in your list—it'll limit the Get Items action to the number entered into the Top Count field.

Return Count of Items

Whenever I use a Filter Query in a Get Items action, I always like to return the count of items returned in a Compose action. This is helpful when building a flow and can also be used to troubleshoot your flow. Tip: Remember to rename your actions to keep things organized. It also makes it easy to identify which dynamic content belongs to which action. 

Insert a Compose action. Ad

 

d an Expression. Use the length() function.

 

Select the Dynamic content tab and insert the value dynamic content from the Get Items action into the length() function.Run a test. Review the output of the Compose action. Because I've specified a top count of 5, the number returned is 5. 

 

Get Details of Random Item

The Get Items action returns an array of items. To return a single item from an array, you need to specify an index. Array index numbers start at 0. The first item index would be 0, then second item would be 1, the third item would be 2 ... and so on.

 

Add a Compose action.

 

Insert the dynamic content that is storing the name. In my case it's the Profile column.

 

Because the Profile column is a person column, I'm using the Profile DisplayName dynamic content. When you insert the dynamic content into your Compose action. Power Automate will automatically nest the Compose action inside an Apply to Each action. This is because the Get Items action returns an array of items.

 

Click on the three dots of the Compose action and select Peek code.

 

Highlight the text after the question mark and before the closing double quotes. Make sure to include the square brackets. Copy this to your clipboard.

Remove the dynamic content label and pull the Compose action OUTSIDE of the apply to each action—delete the Apply to Each action. 

 

In the Compose action, insert an expression. Start with this expression:

?[0]

For this first test we'll use 0 as the index number to return the first item. Later on we'll replace this with a random number.

 

After the index key paste in the content on your clipboard.

Place your cursor at the start of the expression by pressing the up arrow key. Click on the Dynamic content tab and insert the value dynamic content from the Get Items action. 

 

Run a test. Review the output of the Compose action. It should return a name. Keep in mind, this will always return the first item.

 

Note: You could leave your flow as is if you'd like, since you are filtering the SP list by a column—a name would never be posted more than once anyway. The first item would always be a different name.

 

Get a Random Number

If you'd like to return a random item from the array, instead of always returning the first item—you'll need to edit your expression so the index number is a random number.

 

First, let's compose a random number. Add a Compose action to your flow between the Compose action storing the Item Count and the other one storing the Random Name. Insert the rand() function.

 

The rand() function takes two parameters:

rand([min integer],[max integer])

You'll need to specify a number to start at and to end at. The rand() function will output a random number between your start number and end number.

 

For the min integer, enter a 0 and add a comma.

 

Since the array index starts at 0 for the first item, we'll need to subtract 1 from the total number of items returned. This will give us the index of the last item from the Get Items array. Insert the sub() function.

Click on the dynamic content tab and insert the output from the Compose action storing the item count. This is why it's important to name your actions. Otherwise it makes it hard to tell which dynamic content belongs to which action.

 

Add a comma and a 1. 

This expression will return a random number between 0 and the number of items returned from the Get Items action. In my case, between 0 and 5. 

 

Run a test. Run a few tests.. each time you run a test the number should be different. 

Randomize the Name

Now that you have a random number, you can insert the output from the Compose action above into the expression returning the name.

 

To do this click on the dynamic content label for the expression. Highlight the index number and insert the output from the Compose action above.

Run a test.

 

Post Message

Add the Post a message in a chat or channel action. Use the output of the dynamic content from above in your message.

 

While you are testing your flow. Always set yourself as the recipient. Once you've confirmed the flow is working the way you've intended it to work, you can adjust where the message is posted and/or the recipient.

 

Update Item

Add an Update Item action. Don't insert the ID dynamic content from the Get Items action. Otherwise the Update Item will nest itself inside an Apply to Each action. You want to avoid this since you are only updating a single item. 

 

Start with this expression:

?[]

Between the square brackets you need to specify the index number. Insert the output of the random number here. Pay attention to the dynamic content you are selecting. Ensure you are selecting the output of the correct Compose action.

 

Add another set of square brackets and insert ID between single quotes.

Place your cursor at the start of the expression by pressing the UP arrow key. Insert the value dynamic content from the Get Items action. 

Insert any dynamic content that is required into the Update Items action. Remember that you will need to use an expression to do that so you can avoid the apply to each action. You can refer to the tutorial I've linked below. 

 

Sine I've used a Date and Time column to mark those items that have already been posted, I'll insert the Timestamp dynamic content.

 

Run a test.

 

Hope this helps!


If I helped you solve your problem—please mark my post as a solution .
Consider giving me a 👍 if you liked my response! If you're feeling generous— ️  Buy me a coffee: https://www.buymeacoffee.com/acreativeopinion

👉 Watch my tutorials on YouTube
👉 Tips and Tricks on
TikTok
 

 

Take a look a this YT Tutorial I recently uploaded: 3 Mistakes YOU 🫵 are Making with the Apply to Each Action in your Microsoft Power Automate Flow

 

In this video tutorial I’ll go over how to avoid these common mistakes when using the Apply to Each action in a Power Automate flow:

 

1️⃣ Looping through a Single Item

2️⃣ Creating Unnecessary Nested Loops

3️⃣ Looping through an Unfiltered Array

At the end of the video I share a few helpful insights when it comes to using the Apply to Each action in your flow.

 

I'll also cover:

 How to avoid the Apply to Each action with a single item array

 How to use the item() function to access dynamic content in an array

 How to prevent unnecessary nested Apply to Each action loops

 How to use the Select action

 How to convert an array to a string with the Select action

How to use the Filter Query field

 How to count the number of items in an array

 How to use a condition control

 How to use the concurrency control

 How to set a top count

 How to use Compose actions for troubleshooting

 

creativeopinion_43-1707621942284.png

creativeopinion_42-1707621862701.png

creativeopinion_41-1707621827400.png

creativeopinion_40-1707621785474.png

creativeopinion_39-1707621715433.png

creativeopinion_44-1707622112368.png

creativeopinion_37-1707621504909.png

creativeopinion_36-1707621448700.png

creativeopinion_34-1707621406002.png

creativeopinion_32-1707621262061.png

creativeopinion_31-1707621226429.png

creativeopinion_30-1707621198007.png

creativeopinion_29-1707621155840.png

creativeopinion_27-1707621040202.png

creativeopinion_28-1707621113539.png

creativeopinion_16-1707619929650.png

creativeopinion_15-1707619907808.png

creativeopinion_14-1707619892785.png

creativeopinion_11-1707619814694.png

creativeopinion_10-1707619787737.png

creativeopinion_9-1707619773761.png

creativeopinion_7-1707619734327.png

creativeopinion_8-1707619750582.png

creativeopinion_12-1707619824220.png

creativeopinion_5-1707617228441.png

creativeopinion_9-1707608641654.png

creativeopinion_8-1707608600058.png

creativeopinion_26-1707621010540.png

creativeopinion_4-1707617204385.png

creativeopinion_3-1707617193679.png

creativeopinion_0-1707616807422.png

@Lumenia

View solution in original post

Thank you so much!!

View solution in original post

3 REPLIES 3
abm
Most Valuable Professional
Most Valuable Professional

Hi @Lumenia 

 

I can see you have you have got spaces between Name and Surname. You can't use spaces here. So to find out the actual schema name go to SharePoint list > Settings > Click that field name called 'Name and Surname'. This will open a new browser window. Check the browser URL at the end it says field=xxxxx

Copy the field name and use that in your browser.

 

Next you mentioned about the person can be picked only once. So for that you may need to create a boolean field in SharePoint list called 'Picked' (True or False). Then at the end of your flow. Do an update operation to set the flag as true. Also in your List Rows action step add a filter to check whether Picked is false. This way it won't pick again.

 

Thanks

 



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blog
Power Automate Video Tutorials

 Since you've indicated that you want to only post the name once, you will need a way to filter out the names that have already been posted. Add a column to your SharePoint list to store a value. For my SP list, I'll use a Date and Time Column. 

 

Get Items

In the Get Items action, you'll need to specify a filter query. You will need to use the internal column name of your column. Keep in mind that the internal column name may not always match the name displayed in your Sharepoint list. If you aren’t sure how to get this, please refer to this section of one of my YT tutorials.

 

Use the eq (equals to) operator and enter null. This filter query will return items where the Posted on Teams (in my case) Column doesn't contain a value.

 

Specify a Top Count (optional)

Depending on how many items you have in your SP List, I would recommend limiting the Top Count to a smaller number than the total number of items in your list. This will increase the speed of your flow runs. Instead of returning all items in your list—it'll limit the Get Items action to the number entered into the Top Count field.

Return Count of Items

Whenever I use a Filter Query in a Get Items action, I always like to return the count of items returned in a Compose action. This is helpful when building a flow and can also be used to troubleshoot your flow. Tip: Remember to rename your actions to keep things organized. It also makes it easy to identify which dynamic content belongs to which action. 

Insert a Compose action. Ad

 

d an Expression. Use the length() function.

 

Select the Dynamic content tab and insert the value dynamic content from the Get Items action into the length() function.Run a test. Review the output of the Compose action. Because I've specified a top count of 5, the number returned is 5. 

 

Get Details of Random Item

The Get Items action returns an array of items. To return a single item from an array, you need to specify an index. Array index numbers start at 0. The first item index would be 0, then second item would be 1, the third item would be 2 ... and so on.

 

Add a Compose action.

 

Insert the dynamic content that is storing the name. In my case it's the Profile column.

 

Because the Profile column is a person column, I'm using the Profile DisplayName dynamic content. When you insert the dynamic content into your Compose action. Power Automate will automatically nest the Compose action inside an Apply to Each action. This is because the Get Items action returns an array of items.

 

Click on the three dots of the Compose action and select Peek code.

 

Highlight the text after the question mark and before the closing double quotes. Make sure to include the square brackets. Copy this to your clipboard.

Remove the dynamic content label and pull the Compose action OUTSIDE of the apply to each action—delete the Apply to Each action. 

 

In the Compose action, insert an expression. Start with this expression:

?[0]

For this first test we'll use 0 as the index number to return the first item. Later on we'll replace this with a random number.

 

After the index key paste in the content on your clipboard.

Place your cursor at the start of the expression by pressing the up arrow key. Click on the Dynamic content tab and insert the value dynamic content from the Get Items action. 

 

Run a test. Review the output of the Compose action. It should return a name. Keep in mind, this will always return the first item.

 

Note: You could leave your flow as is if you'd like, since you are filtering the SP list by a column—a name would never be posted more than once anyway. The first item would always be a different name.

 

Get a Random Number

If you'd like to return a random item from the array, instead of always returning the first item—you'll need to edit your expression so the index number is a random number.

 

First, let's compose a random number. Add a Compose action to your flow between the Compose action storing the Item Count and the other one storing the Random Name. Insert the rand() function.

 

The rand() function takes two parameters:

rand([min integer],[max integer])

You'll need to specify a number to start at and to end at. The rand() function will output a random number between your start number and end number.

 

For the min integer, enter a 0 and add a comma.

 

Since the array index starts at 0 for the first item, we'll need to subtract 1 from the total number of items returned. This will give us the index of the last item from the Get Items array. Insert the sub() function.

Click on the dynamic content tab and insert the output from the Compose action storing the item count. This is why it's important to name your actions. Otherwise it makes it hard to tell which dynamic content belongs to which action.

 

Add a comma and a 1. 

This expression will return a random number between 0 and the number of items returned from the Get Items action. In my case, between 0 and 5. 

 

Run a test. Run a few tests.. each time you run a test the number should be different. 

Randomize the Name

Now that you have a random number, you can insert the output from the Compose action above into the expression returning the name.

 

To do this click on the dynamic content label for the expression. Highlight the index number and insert the output from the Compose action above.

Run a test.

 

Post Message

Add the Post a message in a chat or channel action. Use the output of the dynamic content from above in your message.

 

While you are testing your flow. Always set yourself as the recipient. Once you've confirmed the flow is working the way you've intended it to work, you can adjust where the message is posted and/or the recipient.

 

Update Item

Add an Update Item action. Don't insert the ID dynamic content from the Get Items action. Otherwise the Update Item will nest itself inside an Apply to Each action. You want to avoid this since you are only updating a single item. 

 

Start with this expression:

?[]

Between the square brackets you need to specify the index number. Insert the output of the random number here. Pay attention to the dynamic content you are selecting. Ensure you are selecting the output of the correct Compose action.

 

Add another set of square brackets and insert ID between single quotes.

Place your cursor at the start of the expression by pressing the UP arrow key. Insert the value dynamic content from the Get Items action. 

Insert any dynamic content that is required into the Update Items action. Remember that you will need to use an expression to do that so you can avoid the apply to each action. You can refer to the tutorial I've linked below. 

 

Sine I've used a Date and Time column to mark those items that have already been posted, I'll insert the Timestamp dynamic content.

 

Run a test.

 

Hope this helps!


If I helped you solve your problem—please mark my post as a solution .
Consider giving me a 👍 if you liked my response! If you're feeling generous— ️  Buy me a coffee: https://www.buymeacoffee.com/acreativeopinion

👉 Watch my tutorials on YouTube
👉 Tips and Tricks on
TikTok
 

 

Take a look a this YT Tutorial I recently uploaded: 3 Mistakes YOU 🫵 are Making with the Apply to Each Action in your Microsoft Power Automate Flow

 

In this video tutorial I’ll go over how to avoid these common mistakes when using the Apply to Each action in a Power Automate flow:

 

1️⃣ Looping through a Single Item

2️⃣ Creating Unnecessary Nested Loops

3️⃣ Looping through an Unfiltered Array

At the end of the video I share a few helpful insights when it comes to using the Apply to Each action in your flow.

 

I'll also cover:

 How to avoid the Apply to Each action with a single item array

 How to use the item() function to access dynamic content in an array

 How to prevent unnecessary nested Apply to Each action loops

 How to use the Select action

 How to convert an array to a string with the Select action

How to use the Filter Query field

 How to count the number of items in an array

 How to use a condition control

 How to use the concurrency control

 How to set a top count

 How to use Compose actions for troubleshooting

 

creativeopinion_43-1707621942284.png

creativeopinion_42-1707621862701.png

creativeopinion_41-1707621827400.png

creativeopinion_40-1707621785474.png

creativeopinion_39-1707621715433.png

creativeopinion_44-1707622112368.png

creativeopinion_37-1707621504909.png

creativeopinion_36-1707621448700.png

creativeopinion_34-1707621406002.png

creativeopinion_32-1707621262061.png

creativeopinion_31-1707621226429.png

creativeopinion_30-1707621198007.png

creativeopinion_29-1707621155840.png

creativeopinion_27-1707621040202.png

creativeopinion_28-1707621113539.png

creativeopinion_16-1707619929650.png

creativeopinion_15-1707619907808.png

creativeopinion_14-1707619892785.png

creativeopinion_11-1707619814694.png

creativeopinion_10-1707619787737.png

creativeopinion_9-1707619773761.png

creativeopinion_7-1707619734327.png

creativeopinion_8-1707619750582.png

creativeopinion_12-1707619824220.png

creativeopinion_5-1707617228441.png

creativeopinion_9-1707608641654.png

creativeopinion_8-1707608600058.png

creativeopinion_26-1707621010540.png

creativeopinion_4-1707617204385.png

creativeopinion_3-1707617193679.png

creativeopinion_0-1707616807422.png

@Lumenia

Thank you so much!!

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (646)