Skip to main content

Notifications

Community site session details

Community site session details

Session Id : vInNhHRDnnm7bKy7F8o7xA
Power Apps - Building Power Apps
Suggested answer

Patch update an existing list item ?

Like (1) ShareShare
ReportReport
Posted on 30 Jul 2024 17:44:16 by 1,597 Super User 2024 Season 1
Hello,
 
I am using the following code on the OnSelect property of the Save button in the screenshot below - this is saving data to two SharePoint lists.
Patch(
    SubtopicArgEvi_1,
    Defaults(SubtopicArgEvi_1),
    {
        Building: DataCardValue1.Text,
        Topic: DataCardValue2.Text,
        Subtopic: SubtopicDD_1.Selected.Value,
        RAGStatus: SubtopicRAGStatusDD_1.Selected.Result,
        'Subtopic Breakdown': SubtopicBreakDownDD_1.Selected.Value,
        Argument: ArgumentText2.HtmlText,
        Evidence: EvidenceText2.HtmlText
    }
);

Patch(
    SubtopicArgEvi_ChangeReq,
    Defaults(SubtopicArgEvi_ChangeReq),
    {
        Building: DataCardValue1.Text,
        Topic: DataCardValue2.Text,
        Subtopic: SubtopicDD_1.Selected.Value,
        RAGStatus: SubtopicRAGStatusDD_1.Selected.Result,
        SubtopicBreakdown: SubtopicBreakDownDD_1.Selected.Value,
        Argument: ArgumentText2.HtmlText,
        Evidence: EvidenceText2.HtmlText
    }
);

Notify("Suptopic successfully saved!");
 
 
 
The SharePoint list 'SubtopicArgEvi_1' is associated with this gallery. When a row is selected, you can select the Edit button to open the form control in a modal dialog (as above).
 
 
In the initial patch statement at the top of this post, it also patches the same edit form data to the list 'SubtopicArgEvi_ChangeReq' - this is where end users in the business will make their changes, submit for approval and once approved, the data in the the 'SubtopicArgEvi_1' will get updated by a power automate flow.
 
 
I just need some help with getting the patch statement for this to work to update the text data in the above Argument and Evidence boxes once they've been edited.
 
I've tried using the 'SubmitForm' command on the SAVE button. however it didn't want that - it wanted to use patch.
 
I've tried using the following but something seems amiss:
 
Patch(
    SubtopicArgEvi_ChangeReq,
    LookUp(
        SubtopicArgEvi_ChangeReq,
    ),
    {
        Building: DataCardValue1.Text,
        Topic: DataCardValue2.Text,
        Subtopic: SubtopicDD_1.Selected.Value,
        RAGStatus: SubtopicRAGStatusDD_1.Selected.Result,
        SubtopicBreakdown: SubtopicBreakDownDD_1.Selected.Value,
        Argument: ArgumentText2.HtmlText,
        Evidence: EvidenceText2.HtmlText
    }
);

Notify("Subtopic Change Request information updated");
Any help or ideas on what to do would be really helpful! :)
Categories:
  • Kalel_Lucas Profile Picture
    165 on 01 Aug 2024 at 19:42:38
    Patch update an existing list item ?
    Hello sudosaurus,
     
    What I meant by it is that if in your ChangeRequestID control, for some reason, had something that isn't a number (like the string "abcdefg", for example), surrounding it with Value() won't work. That seems unlikely to be the case though.
     
    One question: are your Argument and Evidence columns a multi-line text column? If not, they should be, and on top of that, they should have the "Enhanced Rich Text" property enabled:
    Can you confirm that for me?
     
    Kind regards,
    Kalel
  • sudosaurus Profile Picture
    1,597 Super User 2024 Season 1 on 01 Aug 2024 at 09:50:37
    Patch update an existing list item ?
    Hi Kalel,
     
    What did you mean about the ChangeRequestID being made into numbers?
     
    When I press the Saved button on the change request screen, that patch statement appears to be processed however the text changes into the two rich text boxes are not being applied at all to the columns in the SharePoint list.
     
    So, I'm not sure why it's not working?
    Patch(
        SubtopicArgEvi_ChangeReq,
        LookUp(
            SubtopicArgEvi_ChangeReq,ID = Value(ChangeRequestID.Text)
        ),
        {
            Argument: ArgumentText3.HtmlText,
            Evidence: EvidenceText3.HtmlText,
            RAGStatus: SubtopicRAGStatusDD_2.Text
        }
    );
    
    Notify("Subtopic Change Request information updated");
    
     
  • Kalel_Lucas Profile Picture
    165 on 31 Jul 2024 at 00:09:21
    Patch update an existing list item ?
    Hello sudosaurus,
     
    You can surround your ChangeRequestID.Text with Value() so it coerces the value of whatever is in there to a number:
    Value(ChangeRequestID.Text)
    This should allow comparisons as long as the values in ChangeRequestID can be made into numbers.
     
    Hope it helps,
    Kalel
     
  • sudosaurus Profile Picture
    1,597 Super User 2024 Season 1 on 30 Jul 2024 at 23:27:38
    Patch update an existing list item ?
    In response to Kalel,
     
    I inserted my ID field into the form and named it 'ChangeRequestID' (it is a label by default). However it said it was incompatible.
     
  • Suggested answer
    Ryan_B Profile Picture
    446 on 30 Jul 2024 at 20:57:54
    Patch update an existing list item ?
    Without actually trying anything, the first thing that comes to mind is that your LookUp is incorrect.
     
    Just so I'm clear, you want users to edit the data in the list called SubtopicArgEvi_ChangeReq, wait for an approval to happen, then if approved it will send these edits to the main list called SubtopicArgEvi_1 to update the associated record. If so, then here's how you can go about fixing your LookUp.
     
    Since you will be patching both lists at the same time, I would recommend having some sort of unique identifier column (if you don't already have one) that "connects" the two lists. I would say you can probably use the already existing ID column in your lists, but I guess there's a small chance that if multiple people press this button at the same time that the IDs could be different based on how the Patch is handled and at what speed. Once you have a unique identifier, you would simply add it as your LookUp parameter:
    ​​​​​​​
    Patch(
        SubtopicArgEvi_1,
        LookUp(
            SubtopicArgEvi_1, varEditRecord.UniqueIdentifier = UniqueIdentifier,
        ),
        {
            Building: DataCardValue1.Text,
            Topic: DataCardValue2.Text,
            Subtopic: SubtopicDD_1.Selected.Value,
            RAGStatus: SubtopicRAGStatusDD_1.Selected.Result,
            SubtopicBreakdown: SubtopicBreakDownDD_1.Selected.Value,
            Argument: ArgumentText2.HtmlText,
            Evidence: EvidenceText2.HtmlText
        }
    );
    
    Notify("Subtopic Change Request information updated");
    When the user presses the Edit button you will want to capture that selected record into a variable, which I have called varEditRecord in my example above. You will then use record's unique identifier you created to match against in both SharePoint lists.
     
  • Kalel_Lucas Profile Picture
    165 on 30 Jul 2024 at 19:34:12
    Patch update an existing list item ?
    Hello sudosauros,
     
    According to the code you sent there, your LookUp formula is missing its second argument.
    LookUp needs the table/dataset you are going to look info up as the first argument and a criteria for the desired record as the second argument.
    Your code should be something like:
    Patch(
        SubtopicArgEvi_ChangeReq,
        LookUp(
            SubtopicArgEvi_ChangeReq,ID = Textbox.Text
        ),
        {
            Building: DataCardValue1.Text,
            Topic: DataCardValue2.Text,
            Subtopic: SubtopicDD_1.Selected.Value,
            RAGStatus: SubtopicRAGStatusDD_1.Selected.Result,
            SubtopicBreakdown: SubtopicBreakDownDD_1.Selected.Value,
            Argument: ArgumentText2.HtmlText,
            Evidence: EvidenceText2.HtmlText
        }
    );
    
    Notify("Subtopic Change Request information updated");
    The "ID = Textbox.Text" part is just an example, but, ideally, your LookUp should try to search the record with the same ID on the SP list, this way it knows where it needs to update the information.
     
    Hope it helps,
    Kalel

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,660 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,004 Most Valuable Professional

Leaderboard