Skip to main content
Power Automate
    • Connectors
    • Templates
    • Take a guided tour
    • Digital process automation
    • Robotic process automation
    • Business process automation
    • Process advisor
    • AI Builder
  • Pricing
  • Partners
    • Blog
    • Documentation
    • Roadmap
    • Self-paced learning
    • Webinar
    • Business process and workflow automation topics
    • Overview
    • Issues
    • Give feedback
    • Overview
    • Forums
    • Galleries
    • Submit ideas
    • User groups
    • Register
    • ·
    • Sign in
    • ·
    • Help
    Go To
    • Microsoft Power Automate Community
    • Welcome to the Community!
    • News & Announcements
    • Get Help with Power Automate
    • General Power Automate Discussion
    • Using Connectors
    • Building Flows
    • Using Flows
    • Power Automate Desktop
    • Process Advisor
    • AI Builder
    • Power Automate Mobile App
    • Translation Quality Feedback
    • Connector Development
    • Power Platform Integration - Better Together!
    • Power Platform Integrations
    • Power Platform and Dynamics 365 Integrations
    • Galleries
    • Community Connections & How-To Videos
    • Webinars and Video Gallery
    • Power Automate Cookbook
    • Events
    • 2021 MSBizAppsSummit Gallery
    • 2020 MSBizAppsSummit Gallery
    • 2019 MSBizAppsSummit Gallery
    • Community Engagement
    • Community AMA
    • Community Blog
    • Power Automate Community Blog
    • Community Support
    • Community Accounts & Registration
    • Using the Community
    • Community Feedback
    cancel
    Turn on suggestions
    Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
    Showing results for 
    Search instead for 
    Did you mean: 
    • Microsoft Power Automate Community
    • Galleries
    • Power Automate Cookbook
    • Re: Get a random item from a SharePoint list

    Re: Get a random item from a SharePoint list

    11-30-2022 08:36 AM

    jamescosten
    Helper III
    1036 Views
    LinkedIn LinkedIn Facebook Facebook Twitter Twitter
    RobElliott
    Super User RobElliott
    Super User
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    Get a random item from a SharePoint list

    ‎02-06-2020 03:43 AM

    There might be times when you want to get a random item from a SharePoint list. My list of Towns and Counties in the UK has about 1800 items in it and I want to get a random town once a day.

    1. I've started with a Recurrence schedule as the trigger.

    2. The first action is the SharePoint Get items.
    0-recurrence-getItems.png

    As my list has more than 100 items I have set Pagination on with a threshold of 2000 in the settings for Get items: 

    0a-getItems-Settings.png

    3. Next, add a Compose control and add the following expression:

    body('Get_items')?['value'][rand(1,length(body('Get_items')?['value']))]

    1-composeRand.png

    4. At this point save the flow and test it. In the test results copy everything in the Output panel of the Compose:

    2-run-copyComposeOutput.png

    5. Next, edit the flow again and add a Parse JSON and from the dynamic content select the output from the Compose for the Contents field. Click Generate from sample and paste in the Schema code you copied at #4 above:

    3-parseJSON.png

    6. From the dynamic content you can now select the items from the Parse JSON to use in further actions in your flow. I'm just sending an email to myself but you could assign a task in planner, add the town to another list, use it to select a winner from a competition, where to go on your next vacation and for other uses where you want a random result from the SharePoint list:

    4-sendEmail.png

    The following is the result with a random town from the list:

    5-emailResult.png

    Rob

    Los Gallardos

    Preview file
    8 KB
    RandomSharePointListItem_20200206114214.zip
    Labels:
    • Labels:
    • Button flows
    • List
    • random
    • SharePoint
    Message 1 of 6
    8,486 Views
    3 Kudos
    Reply
    • All forum topics
    • Previous Topic
    • Next Topic
    Anonymous
    Not applicable
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎11-11-2021 03:01 AM

    Great tip, thank you very much!

    Message 2 of 6
    5,273 Views
    0 Kudos
    Reply
    magichappens89
    magichappens89
    Regular Visitor
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎11-19-2021 04:31 AM

    Anyone tried this out for a couple of runs? At least for me this never picks the items that are at the beginning or at the end so it´s not working very reliable.

    Message 3 of 6
    5,112 Views
    0 Kudos
    Reply
    RobElliott
    Super User RobElliott
    Super User
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎11-19-2021 04:57 AM

    @magichappens89 yes I've had a couple of these running every day for about 3 years. Don't forget that being random it won't necessarily select an item, but then might pick it 3 times running....or not at all!

     

    1-PA.png

    Rob
    Los Gallardos
    If I've answered your question or solved your problem, please mark this question as answered. This helps others who have the same question find a solution quickly via the forum search. If you liked my response, please consider giving it a thumbs up. Thanks.

    Message 4 of 6
    5,109 Views
    0 Kudos
    Reply
    magichappens89
    magichappens89
    Regular Visitor
    In response to RobElliott
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎11-19-2021 05:36 AM

    I considered this but I only have 5 items and its pretty obvious its not picking the first and the last entry. I will try changing it to body('Get_items')?['value'][rand(0,length(body('Get_items')?['value']))] as I guess the first entry is 0 not 1. But that doesn´t explain why its not getting the last one.

    Message 5 of 6
    5,108 Views
    0 Kudos
    Reply
    jamescosten
    jamescosten Helper III
    Helper III
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎11-30-2022 08:36 AM

    How do i return multiple randoms items, it is returning 1 itme but i would like 5.

    Message 6 of 6
    1,036 Views
    0 Kudos
    Reply

    Power Platform

    • Overview
    • Power BI
    • Power Apps
    • Power Pages
    • Power Automate
    • Power Virtual Agents

    • Sign up free
    • Sign in

    Browse

    • Templates
    • Connectors
    • Partners

    Downloads

    • Mobile
    • Gateway

    Learn

    • Documentation
    • Learn
    • Support
    • Community
    • Give feedback
    • Blog
    • Pricing

    • © 2023 Microsoft
    • Contact us
    • Trademarks
    • Privacy & cookies
    • Manage cookies
    • Terms of use
    • Terms & conditions
    California Consumer Privacy Act (CCPA) Opt-Out Icon Your California Privacy Choices