cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Resident Rockstar
Resident Rockstar

Update() function now irreconcileable after adding a Primary KEY index.

I went through great pains to add a primary key to my SQL table so that Patch() and Collect() would work properly.  I also wish to use Update().  Its just a cleaner way to update an entire record in one go.  However, Since the table now has an automatic key, I cant make it go.  If I leave my key column out of my Set() variable, then the command failes because the column is missing.  If I add the column, even if Blank(), it returns: "The specified column is generated by the server and can't be specified."  So, its a Darned if you do, darned if you don't scenario.  I guess Update() is just not applicable with a table with a index??

 

image.png

 

BTW, Collect() works in a similar fashion.  It works fine.  I guess adding a new row to the table is not affected in the same way.

3 REPLIES 3
Highlighted
Power Apps
Power Apps

Re: Update() function now irreconcileable after adding a Primary KEY index.

Hi @martinav ,

There are a few functions to help update a table: Update, UpdateIf, and Patch.

 

UpdateIf and Patch do not require you to replace the entire row with another full row, so they would be the functions to use in this case.

 

The Update function requires you to replace an entire row with another full row. But as you have found out, if you have a column whose values must be unique (and it's identity is auto-generated), then this will not work.

 

Here's the doc in question:

Update function
Use the Update function to replace an entire record in a data source. In contrast, the UpdateIf and the Patch functions modify one or more values in a record, leaving the other values alone.

For a collection, the entire record must match. Collections allow duplicate records, so multiple records might match. You can use the All argument to update all copies of a record; otherwise, only one copy of the record is updated.

If the data source generates a column's value automatically, the value of that column must be reaffirmed.

Source: https://docs.microsoft.com/powerapps/maker/canvas-apps/functions/function-update-updateif

 

@timl @v-xida-msft @seadude who can field some additional questions you might have about Patch

Highlighted
Super User
Super User

Re: Update() function now irreconcileable after adding a Primary KEY index.

I LOVE UpdateIf() !
Great use cases:

  • OnChange/OnCheck/OnUncheck of Dropdown/Textbox/Checkbox/Toggles both stand-alone, in Forms and (especially!) in Galleries.
    • Example:
    • If(
          dropdown.Selected.Value <> "defaultValue",
          UpdateIf(
              collectionName,
              id = 23 //whatever id OR ThisItem.ID in a Gallery
              {
                  specific field: "toUpdate",
                  other field: "toUpdate"
              }
          )
      )
  • I've been using this a LOT lately for Progress Bars on long forms.
Highlighted
Super User
Super User

Re: Update() function now irreconcileable after adding a Primary KEY index.

PS: I've found Patch does NOT work for Collections of items from Sharepoint lists, @RandyHayes (I think) aimed me at UpdateIf to Patch Collections from SP lists. After reading @Mr-Dang-MSFT 's comment above RE: unique items, I think I now know WHY!

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (8,112)