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 Apps / Patch Code for Form No...
Power Apps
Unanswered

Patch Code for Form Not Working

(0) ShareShare
ReportReport
Posted on by

I am building a 2 page form. Page 1 the end user fills out with some info. Then at some later date, the admin team opens the item, clicks the button that is visible only to them, and goes to page 2 to fill out more info. I have tried a variety of codes to write the page 2 data back to the original item that was created from submitting page 1, but nothing seems to work. This is a form without a gallery. What does not work:

Patch('List Name',Defaults('List Name'),{'Comments': DataCardValue12})

Patch('List Name',Defaults('List Name'),SharePointForm1.Updates,AdminForm.Updates)

^^ Note that neither of these indicate an error in the form designer and both create new records rather than updating the existing record

This does not throw an error in the form designer, either, but gives the dreaded "must implement iConvertible" error. I removed and re-added my data source, but that didn't solve the problem.

Patch('List Name',LookUp('List Name',ID = varID.Text,{Comments:DataCardValue12}))

I'm out of ideas. Any suggestions would be most welcome.

Categories:
I have the same question (0)
  • EddieE Profile Picture
    4,641 Moderator on at

    @Anonymous 

    What is the Item property of the form, if two forms, both Items.

     

    If your Item property is setup correctly, all you need to do is use SubmitForm(yourFormName). Using Defaults() will always create a new record.

     

  • Verified answer
    RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @Anonymous 

    When you split a form like that and try to use patch with it, you are wasting all the functionality of the forms themselves and you will have to write your own formulas to try and produce the same results.

     

    First take a look over this video on splitting forms properly to see how to split your forms and maintain the functions and features of the form and then utilize the SubmitForm function to submit your form and you will have none of the issues you are dealing with.

     

    Beyond that, you are not specifying the record you want to patch in your formulas.  You are using Defaults in the first, which will be an empty record - meaning that Patch will create a record.

     

    Your last formula is using a Lookup, but it is not formatted properly.  How are you getting the ID of the record in your form?  That is what is needed in the Patch function.

     

    I hope this is helpful for you.

  • Community Power Platform Member Profile Picture
    on at

    I have the ID data card value and when you click the button to go to the 2nd page, it sets a variable (varID) with the item ID.

    I'll watch the video.

  • Community Power Platform Member Profile Picture
    on at

    Form 1:

    If(IsBlank(SharePointIntegration.Selected) || IsEmpty(SharePointIntegration.Selected),First([@'List Name']),SharePointIntegration.Selected)

     

    Form 2:

    SharePointForm1.Updates

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

    @Anonymous 

    So then you are partly there with your Item properties.  Just make Form 2 your master form (watch the video) and you can submit that form.

     

    Beyond that, if you leave the forms broken, then the patch statement would be:

        Patch('List Name', {ID: varID, Comments:DataCardValue12.Text})

    You just need to include the ID - the primary key. (and you need to specify the correct property of your DataCardValue12 control too!)

  • Community Power Platform Member Profile Picture
    on at

    This video is for an app, not a form. Will it still apply to my form?

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

    @Anonymous 

    It is forms.  It happens to be in a standalone app, but the concept is exactly the same and works the same.

     

  • Community Power Platform Member Profile Picture
    on at

    So it looks like I went down the wrong path. Either I redesign based on your video or tweak my patch code. I understand the pitfalls of keeping the form broken. I think at this point I'd like to get the patch working, then take my time redesigning it and doing it right. So my code that throws the IConvertible error:

    Patch('List Name',LookUp('List Name',ID = varID.Text,{Comments:DataCardValue12}))

    is wrong? I need to tweak it to match your code:

    Patch('List Name', {ID: varID, Comments:DataCardValue12.Text})

    and basically eliminate the LookUp? Your code looks like I'm writing the value of the varID back to the ID column, which I shouldn't be able to do.

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

    @Anonymous 

    No, you can never set an ID.

    But that is not the purpose.  Patch is an intelligent function.  If you provide the primary key (the ID in this case) in your record, then patch will know to update the record with that ID.  If the ID is Blank, then Patch will create a record.

    That is all you need to do!

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 Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard