web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / The template language ...
Power Automate
Unanswered

The template language expression cannot be evaluated because array index '24' is outside bounds (0, 23) of array.

(0) ShareShare
ReportReport
Posted on by 65

Hi friends, I'm trying to build a flow that take certain names of a group from one SP list, randomizes and pairs them, and prints them in pairs to another SP list. I am SO close, but keep running into this error: The template language expression  'outputs('Compose_format_names')[mul(variables('Count'),2)]['Name']' cannot be evaluated because array index '24' is outside bounds (0, 23) of array. Otherwise, the flow prints 11 out of 12 pairs for me, no issue. 

 

This topic helped me get to where I am (thank you @v-bofeng-msft ) but I've made some modifications to ensure better randomizing. See images attached. 

 

I'm sure the fix is simple enough, but I don't see what it is or where to put it. Thanks in advance to the kind soul(s) who point me in the right direction. 

 

jmathur_0-1673055089109.png

jmathur_1-1673055092887.png

 

jmathur_2-1673055102431.png

jmathur_3-1673055114681.png

 

jmathur_4-1673055123336.png

 

jmathur_5-1673055127096.png

 

jmathur_6-1673055131532.png

jmathur_7-1673055136418.png

 

jmathur_8-1673055140312.png

Categories:
I have the same question (0)
  • jmathur Profile Picture
    65 on at

    Realized I can add photos directly in window - edited comments/post appropriately.

     

  • grantjenkins Profile Picture
    11,063 Moderator on at

    @jmathur I'm just popping out for a few hours but will build a flow that should get what you want, and a lot easier/simpler than what you currently have.

     

    Are you able to show what your two lists look like with regards to the data (sample data is fine)?

    • Member Reporters
    • Peer Reviewer Pairs
  • jmathur Profile Picture
    65 on at

    I love easier and simpler. 

     

    Here's an example of Member Reporters. I have 25 values in it - 24 of whom should be paired up. I reference one single line text column and a choice column for Include in reviews.  

     

    jmathur_0-1673056488895.png

     

    Here's an example of peer reviewer pairs. I just use single line text columns in this one. I was using the Title column values to tell the flow which values still needed to be updated. If you have any idea how to tell the flow when to add/delete rows based on the number of values from the first list, all the better. Let me know if I can give any more info. 

     

    jmathur_1-1673056667374.png



     

  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    @jmathur This is how I would go about what you were trying to achieve. I would actually delete all the existing items in the Peer Review Pairs list, then create new items with the updated pairings. It would also cater for even/odd number of employees.

     

    For this example, I have the following lists based of what you provided.

     

    grantjenkins_0-1673149421849.png

     

    grantjenkins_1-1673149461156.png

     

    Full flow below. I'll go into each of the actions.

    grantjenkins_4-1673149734599.png

     

    Recurrence runs quarterly as what you already have.

    grantjenkins_3-1673149586250.png

     

    Next, we want to delete all the existing items in the Peer Reviewer Pairs list.

     

    Get items PRP retrieves all the items from the list.

    grantjenkins_5-1673149810034.png

     

    Apply to each PRP iterates through each item and deletes it so we end up with an empty list.

    grantjenkins_6-1673149853675.png

     

    Next, we want to retrieve the employees so we can match them.

     

    Get items MR retrieves all the items from the Member Reporters list where Include In Reviews is equal to Yes.

    grantjenkins_7-1673149948402.png

     

    Select Employees maps the Employee Name and a random number between 1 and 100. The expression used to generate the random number for each employee is:

    rand(1,100)

    grantjenkins_8-1673150035253.png

     

    Order Employees is a Compose that uses a sort expression to sort the employees by Order. This will give us our randomized list of employees. The expression used is:

    sort(body('Select_Employees'), 'Order')

    grantjenkins_9-1673150119911.png

     

    Apply to each uses the output from Order Employees and chunks them into groups of 2. This will give us our employee pairings. The expression used is below. The first iteration will contain the first two items, the second iteration will contain the 3rd and 4th items, etc.

    chunk(outputs('Order_Employees'), 2)

    grantjenkins_10-1673150241035.png

     

    We then have a Condition to ensure we have two items in the current iteration. If the number of employees is an even number, then the Condition would always be true. But if the number of employees is an odd number then the last iteration would only have one item, so we would just ignore this one. The expression to check the length is:

    length(items('Apply_to_each'))

    grantjenkins_11-1673150360630.png

     

    If the length of employees is two (Condition is true) then we use Create item to add the employee pairings. The expressions used are:

    //Partner 1 (Title)
    first(items('Apply_to_each'))?['Employee']
    
    //Partner 2
    last(items('Apply_to_each'))?['Employee']

    grantjenkins_12-1673150463596.png

     

    Finally, we have our Send an email to email the employees a link to the updated list of pairings.

    grantjenkins_13-1673150517180.png

     

    After running the flow, we would end up with a list of randomized employee pairings:

    grantjenkins_14-1673150557337.png

     

    And our email:

    grantjenkins_15-1673150627314.png


    ----------------------------------------------------------------------
    If I've answered your question, please mark the post as Solved.
    If you like my response, please consider giving it a Thumbs Up.

  • jmathur Profile Picture
    65 on at

    Color me amazed. This worked beautifully, and you're right, so much more simply than my original solutions. Thank you for your time and expertise! 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard