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 / Forall patch Gallery I...
Power Apps
Answered

Forall patch Gallery Items. New item if not exists. else Update

(0) ShareShare
ReportReport
Posted on by 539

Hello, 
i want to Patch a List of Gallery items into my SP List.

If the title already exists i only want to Update the 2 columns trigger and test.

If it does not exists i want to also Patch the Title,trigger and test column.

 

This is my formula. I cant seem to think of a solution.

 

ForAll(Gallery1.AllItems,

 If(LookUp(hwtriggertest,Title = Title2.Text).Title,

 Patch(
 hwtriggertest,First(Filter(hwtriggertest,Title , Title2.Text)),
 {
 trigger: "trigger",
 temp: "1"
 }
 ),
 Patch(
 hwtriggertest,
 {
 Title:Title2.Text,
 trigger: "trigger",
 temp: "1"
 })))

 

 Best regards Niklas

Categories:
I have the same question (0)
  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @niklasjegg 

    Your ForAll is backward as ForAll produces a table and is not a For/Loop.

     

    Please consider changing your Formula to the following:

    Patch(
     hwtriggertest,
     ForAll(Gallery1.AllItems,
     With({_item: LookUp(hwtriggertest, Title = Title2.Text)},
     {
     ID: _item.ID,
     Title: Title2.Text,
     trigger: "trigger",
     temp: "1"
     }
     )
     )
    )

     

    This will give you what you are looking for. 

     

    I hope this is helpful for you.

  • niklasjegg Profile Picture
    539 on at

    @RandyHayes  thank you so much. This works like a charm!

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @niklasjegg 

    Very good!

    I should have mentioned, the key to what is going on is that you are sending a table (from the ForAll) of records to the Patch function.  It knows what to do with a table of records (and does it better than the other way around).

    The bigger key is (no pun intended) the primary key - if the LookUp finds a matching record, then there will be an ID in _item.ID.  If it finds no record, then ID will be blank.

    Patch knows that if it has a primary key (ID) in the record, to update that record in the datasource.  If if encounters a blank ID, then it knows to create the record.

     

  • niklasjegg Profile Picture
    539 on at

    hi @RandyHayes  i just edited my datasource to my Live SP List. Now i get the Following errors.

     

    Invalid argument type (table) expecting a record value.

    And: the function patch has some invalid arguments.

    Patch(
     'HW-Trigger',
     ForAll(Gallery1.AllItems,
     With({_item: LookUp('HW-Trigger',Title = Title2.Text)},
     {
     ID: _item.ID,
     Title: Title2.Text,
     trigger: "trigger",
     temp: "1"
     }
     )
     )
    )

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @niklasjegg 

    Can you go to that formula and then click inside the formula so that you see red underlines and then send a screenshot of it?  That will help determine the issue.

    But before that...are the column names the same??  They must be identical.

  • niklasjegg Profile Picture
    539 on at

    @RandyHayes  im sorry the trigger column was names Trigger and trigger.

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @niklasjegg 

    Yep...that will do it!

    It's a little misleading on the error message because it is saying that Patch wants a record, not a table.  But it takes a table perfectly well.  The problem is that the schema produced in the table does not match the schema of the datasource - but rather than giving an error message that would be so clear - it gives the mysterious "needs a record, not a table".

     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 358 Most Valuable Professional

#2
11manish Profile Picture

11manish 214 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 185

Last 30 days Overall leaderboard