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
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (1,047)