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
Super User
Super User

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
Super User
Super User

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

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (3,183)