cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ProcompsER
Regular Visitor

Help Selecting a random element from array

Hello, hoping for a little assistance,

I am creating a birthday announcement automation for my organization. I'm using a dataverse connector to get contact info from D365, OneDrive to write to an Excel file for testing, and email, to test sending the message. I am trying to store a list of birthday quotes in an array, and then pick a random item from that list later in a for each loop and use it in a email/excel.  The trouble that I am having is that when I attempt to select a random item and store it in a variable, it appears that the variable is blank.  

Here's what I have:

I declare the array variable and set the value.

I declare the variable to hold the selection being picked from the array, (leaving it blank so I can set its value next).  (ignore the comment, that was from a previous try)

Within my for each loop, I attempt to set the variable with this expression

body('varBdayQuotes')?['value'][rand(0,length(body('varBdayQuotes')?['value']))]

When I test the flow, the variable varCurrentQuote appears to be empty.

AllCaptures1.png

 

 

Any help would be appreciated, thanks!

 

-ER

1 ACCEPTED SOLUTION

Accepted Solutions
Rahber
Solution Sage
Solution Sage

I think you mixed the tutorial you were following. The body and how that was for a SharePoint action of Get Item. 

 

Since because you are using an array variable to store your birthday quotes try using this expression

 

variables('varBdayQuotes')[rand(0,length(variables('varBdayQuotes')))]

 

Please click Accept as Solution if it resolved your problem or give it a Thumbs Up if it helped you in anyway this will allow other people to search correct solutions effectively.

Thanks,
Rahber

View solution in original post

1 REPLY 1
Rahber
Solution Sage
Solution Sage

I think you mixed the tutorial you were following. The body and how that was for a SharePoint action of Get Item. 

 

Since because you are using an array variable to store your birthday quotes try using this expression

 

variables('varBdayQuotes')[rand(0,length(variables('varBdayQuotes')))]

 

Please click Accept as Solution if it resolved your problem or give it a Thumbs Up if it helped you in anyway this will allow other people to search correct solutions effectively.

Thanks,
Rahber

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (2,982)