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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Function syntax error ...
Power Apps
Answered

Function syntax error trying to create new records via Patch function inside of ForAll function on Dataverse/CDS

(0) ShareShare
ReportReport
Posted on by 22

Hello all,

 

I am building an app that will be used to gamify sports practice sessions. The app has tables for Game Types < Round Types < Station Types < Result types (where < indicates a 1:N relationship). These tables are used to define the game, define one or more rounds in the game, define one or more stations in a round, and define one or more results per station. For example, a basketball shooting game might consist of a short shot round which consists of 5 stations on the court, and a long shot round which consists of 5 different stations on the court. Results for each station will then be captured and points awarded. For example how many attempts are allowed (5), how many were successful (1 point each), and were all attempts at that station successful (3 points). So if a player is at the free throw station in the long shots round, and if they take 5 shots and make all 5 of them, they get 8 points (1 for each shot made and 3 for making all shots at the station) before moving on to the next station in the round. Then the points get added up for the station (as above), the round (add all station points), and the game (add all round points).

 

Each time a game is played, the results are captured in a set of related tables; Game Instance < Round Instance < Station Instance < Result Instance. So for the above example, there will be one record in Game Instance, 2 records in Round Instance, 10 records in Station instance (5 stations in each of 2 rounds), and 20 records in Results Instance (2 results per station; shots made and all shots made).

 

When a player begins a new game, they will select the type of game they are playing from a gallery of Game Types, select their player from a gallery of players (from a Player Table), and then press the New Game button. At this point, I need the app to create all of the records necessary to play the game and record the results using the Game Type and related Round Type and related Station Type and related Results Type records.  In our example, I need the app to create 1 Game Instance record, 2 Round Instance records, 10 Station Instance records, and 20 Result Instance records, each related back to its parent.

 

Once these records are created, the app will lead the player through each station, collecting results and assigning points for each station until all of the stations in all of the rounds in the game are completed.

 

My idea is to use some nested ForAll statements to Patch each new Instance record based on the various Type records and their relationships as defined for the Game Type chosen. The patching to create the new Game Instance record based on the selected Game Type and Player is easily done. In the interest of taking baby steps, I have presented a list of Game Instances that were created this way in a gallery called galGames. I then added another gallery called galRoundTypes that displays a list of Round Types that are related to the Game Type that is related to the Game Instance record that is selected in the galGames gallery using this formula for Items:

 

galGames.Selected.'Game Type'.'Round Types'

 

This works fine. I then added a button called Create Round which creates a (single) new Round Instance record that is related to the Game Instance that is selected in the galGames gallery and to the Round Type that is selected in the galRoundTypes gallery using this formula for OnSelect:

 

Patch(
  'Round Instances',
  Defaults('Round Instances'),
  {'Round Type': galRoundTypes.Selected},
  {'Game Instance Number': galGames.Selected}
)

 

This also works fine. However, in order to create all of the Round Instance records I need to select each Round Type record listed in the galRoundType gallery and then hit the Create Round button since the button only creates one Round Instance record at a time.

 

Of course, what I really want is to use a ForAll function to cycle through the Round Type records and create a new Round Result record for each one. So I created a new button called Create Rounds and set the OnSelect property to this:

 

ForAll(
  galGames.Selected.'Game Type'.'Round Types',
  Patch(
    'Round Instances',
    Defaults('Round Instances'),
    {'Round Type': galRoundTypes.Selected},
    {'Game Instance Number': galGames.Selected}
  )
)

 

As you can see, this is an attempt to combine the two items that were individually successful into a single ForAll function so it creates all of the Round Instance records at once.  Powerapps does not like the formula, however. Specifically, it does not like 'Round Instances' for the Defaults argument in the Patch Function. The error when hovering over it is:

 

The specified column is not accessible in this context.

 

RandyBristol_0-1610239998258.png

 

Of course the 'Round Instances' worked fine as the Defaults argument when patching to the 'Round Instances' table when it was outside of the ForAll function, so why is it having trouble inside the ForAll function? How can I update my formula to patch records using ForAll?

 

RandyBristol_1-1610240241548.png

 

 

 

Categories:
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    155,315 Most Valuable Professional on at

    Hi @RandyBristol <
    Assuming you want to patch all items in the gallery as new records (and the field names are the same as the target list, you would do this

    ForAll(
     galGames.AllItems As aGames,
     Patch(
     'Round Instances',
     Defaults('Round Instances'),
     {
     'Round Type': aGames.'Round Type',
     'Game Instance Number': aGames.'Game Instance Number'
     }
     )
    )

     Is this what you are after? If not, how do you select multiple items from the gallery?

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • RandyBristol Profile Picture
    22 on at

    Hi @WarrenBelz ,

     

    Your suggested formula does not meet my requirements directly, however it gave me the idea to rename my table and this turned out to work! Not sure exactly why, I suspect I need to study up on scope and disambiguation. Thanks for your response to my isse.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 899

#2
Valantis Profile Picture

Valantis 571

#3
11manish Profile Picture

11manish 499

Last 30 days Overall leaderboard