cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JoepTh
Frequent Visitor

Patching record in Sharepoint list only works one time, not repeatedly

Hello,

 

I have a sharepoint list and built an app to show data and allow the user to change data. I'm not using a form to modify the data (probably making my life harder this way).

 

When the user selects an item in a gallery I store the record in varRecord. Then they make the changes in any input or selection field. Once done, they can hit save and I patch the data back to the list like below. This all works fine. However, when the user goes back to the same record and makes another change, Powerapps doesn't allow to store that change when I hit save. It also gives an error on the code syntax which isn't there before.

Any suggestion is welcome.

 

 

 

Patch(
    Projects,
    LookUp(
        Projects,
        ID = varRecord.ID
    ),
    varRecord
)

 

 

 

Thanks,

 

Joep 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@JoepTh 

EditForms in PowerApps are one of the most powerful tools you can use.  They will save you more time than ever and are very flexible.  Having to "build it yourself" is just more work than you need.  Plus forms bring a huge amount of built-in error checking, validation, change indication and more.  That all said, one thing many don't realize is that you can use EditForms and NOT use the standard form interface that it provides - as that interface is far from flexible as one might like.  You might be interested in watching my video on the topic of EditForms.  It is a very lengthy video as it covers about every aspect of forms that you would ever want to know.   There is a table of contents in the description of the video that will take you to parts of interest.  In your particular scenario, Part 3 - Super Forms at 1:10:39 will be most interesting I believe.

 

To demonstrate a little of the simplicity of the form, what you are trying to do is all done in the OnSuccess of the form.  Your formula there would be Set(varRecord, Self.LastSumbit)  Note that this is On Success...so this is part of the error checking that forms bring.

 

That said again, for your scenario, you would do well to change your patch formula to the following:

Set(varRecord,
    Patch(Projects,
        LookUp(Projects, ID = varRecord.ID),
        varRecord
    )
)

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

5 REPLIES 5
RandyHayes
Super User
Super User

@JoepTh 
Yes, definitely making your life harder by not using a form for this.

 

Be that as it may, what I am not seeing from your Formula is - you say you are setting varRecord to the gallery item, then you are using that in your formula, but where do all of your control values for the record you are changing come into play?  I am not seeing anything other than you are looking up the record and then patching it with the same record.

Can you elaborate on your scenario a bit more?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

I don't like the limitation in the formatting of the forms and want to have the flexibility to create my own screens with the relevant information.

 

So I'm placing the control items in edit mode, then the user can change items and I store them in the varRecord variable as such:

 

Set(varRecord,Patch(varRecord,{ProjectName:Self.Text}))

 

Then, when all the changes are done, they can press save and I'm patching the changes back into the sharepoint list as above.

This works well the first time but if the user goes back into the record to make a change and not selects the record again, I get this error: {VersionNumber}: The specified column is read-only and can't be modified.

Now noticed that the VersionNumber is also stored in varRecord and keeps the previous number so that's probably causing the problem.

 

RandyHayes
Super User
Super User

@JoepTh 

EditForms in PowerApps are one of the most powerful tools you can use.  They will save you more time than ever and are very flexible.  Having to "build it yourself" is just more work than you need.  Plus forms bring a huge amount of built-in error checking, validation, change indication and more.  That all said, one thing many don't realize is that you can use EditForms and NOT use the standard form interface that it provides - as that interface is far from flexible as one might like.  You might be interested in watching my video on the topic of EditForms.  It is a very lengthy video as it covers about every aspect of forms that you would ever want to know.   There is a table of contents in the description of the video that will take you to parts of interest.  In your particular scenario, Part 3 - Super Forms at 1:10:39 will be most interesting I believe.

 

To demonstrate a little of the simplicity of the form, what you are trying to do is all done in the OnSuccess of the form.  Your formula there would be Set(varRecord, Self.LastSumbit)  Note that this is On Success...so this is part of the error checking that forms bring.

 

That said again, for your scenario, you would do well to change your patch formula to the following:

Set(varRecord,
    Patch(Projects,
        LookUp(Projects, ID = varRecord.ID),
        varRecord
    )
)

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

Thanks Randy, watched your video and implemented like such. Great solution.

 

Just still struggling with some form.unsaved and form.valid which are not resetting as expected, probably have to go through again item by item.

 

Thanks,

Joep

RandyHayes
Super User
Super User

@JoepTh 

Form.Unsaved trips a LOT of people up.   The key is this - if your Default property value of a datacard does not equal the Update property of the Datacard, then the form considers it Unsaved.

 

For simple fields in your form, you can make a troubleshooting step of setting the Fill property of each data card to: 

  If(Self.Default <> Self.Update, Red, White)

(or whatever colors you want).  The key is that it will show you very quickly a datacard that is changed.

If it shows changed and you feel it shouldn't, then you need to look to see where it is getting its update property value from and correct as needed.

 

One thing often that causes issues is that you have a text field and initially it is blank/null in the record (existing or new) and you are getting the actual value for the field from another textinput control text property.

In that scenario, the Default of the datacard will be blank/null and the Update property will be "" (an empty string) - which is not blank or null.  So you can coalesce the Default property of the datacard with : Colaesce(ThisItem.FieldName, "")  (and actually a couple of ways to go about it - but that is the concept).

 

For more complex datacards (choice columns, lookups, etc) the above formulas have to be adjusted.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,953)