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 / Saving button is not g...
Power Apps
Unanswered

Saving button is not generating the right data

(0) ShareShare
ReportReport
Posted on by 146
Hello everyone!
 
I have a code for my save button as below:
 
UpdateContext({SaveButtonPressed: true});
Set(
    ChangeNumberVar,
    Text(
        Value(DataCardValue22.Text),
        "[$-en-GB]$#,###.00"
    )
);
SubmitForm(Form5);
Set(
    showFormButtons,
    false
);
// Reset the visibility of the buttons
Patch(
    [@'Invoice Master'],
    LookUp(
        'Invoice Master',
        ID = Last(
            Sort(
                'Invoice Master',
                ID,
                SortOrder.Ascending
            )
        ).ID
    ),
    {'Request ID': DataCardValue10.Text}
);
Patch(
    [@'Expense Claim Automation'],
    LookUp(
        'Expense Claim Automation',
        Text(ID) = DataCardValue10.Text
    ),
   
    {
        'Total Amount:': Sum(
        Filter(
        Gallery3.AllItems,'Request ID' = Text(Gallery2.Selected.ID)),
        Amount)
    }
)
 

Background:

I'm building a Power App that integrates with two SharePoint lists for managing expense claims and invoices. Here’s an overview of the workflow:

  1. SharePoint List 1 (Expense Claim Automation): This list stores basic user information. On the app's initial screen, users fill in this basic information, and when they click on the "Create Invoice" button, the data is submitted to SharePoint List 1. Submitting this form first ensures that the SharePoint ID is generated automatically.

  2. SharePoint List 2 (Invoice Master): After submitting the basic information, users are redirected to an invoice screen where they can input more detailed information. When they finish, they click "Save," and this data is supposed to be submitted to SharePoint List 2.

Issue:

Currently, the detailed information from the invoice screen (SharePoint List 2) is not updating correctly. For example, when User A (ID=1) completes and submits an invoice, their data is saved correctly. However, when User B (ID=2) submits their invoice, instead of creating or updating their unique entry in SharePoint List 2, it overwrites or reuses the data associated with User A’s ID.

This means new user entries are not correctly saved in SharePoint List 2 and are instead referencing the previous user’s data, leading to data inaccuracies.

Request:

Could you assist in troubleshooting why the SharePoint List 2 submission does not capture the new user's data and instead references previous submissions? I'm aiming to ensure that each user's submission in SharePoint List 2 reflects their individual information based on their unique ID from SharePoint List 1

Categories:
I have the same question (0)
  • Suggested answer
    mmbr1606 Profile Picture
    14,605 Super User 2025 Season 2 on at
    hey
     
     
     
    can u try this approach:
    UpdateContext({SaveButtonPressed: true});
    Set(
        ChangeNumberVar,
        Text(
            Value(DataCardValue22.Text),
            "[$-en-GB]$#,###.00"
        )
    );
    SubmitForm(Form5);
    Set(
        showFormButtons,
        false
    );
    Patch(
        [@'Invoice Master'],
        Defaults('Invoice Master'),
        {
            'Request ID': DataCardValue10.Text,
            'Change Number': ChangeNumberVar
        }
    );
    Patch(
        [@'Expense Claim Automation'],
        LookUp(
            'Expense Claim Automation',
            Text(ID) = DataCardValue10.Text
        ),
        {
            'Total Amount:': Sum(
                Filter(
                    Gallery3.AllItems, 
                    'Request ID' = Text(Gallery2.Selected.ID)
                ),
                Amount
            )
        }
    )
    
    if it helped please mark as verified answer
     
     
     
    cheers
  • Suggested answer
    ronaldwalcott Profile Picture
    3,847 Super User 2025 Season 2 on at
    How does this identify the correct user?
     
    LookUp(
            'Invoice Master',
            ID = Last(
                Sort(
                    'Invoice Master',
                    ID,
                    SortOrder.Ascending
                )
            ).ID
    Isn't it just grabbing the last record?
  • Seth18 Profile Picture
    146 on at
    hi @mmbr1606,
     
    I tried with your code it only submitting the amount while other info suddenly all wiped off. 
     
     
     
     
     
     
  • Seth18 Profile Picture
    146 on at
     
    That a good point but how can i fix that part tho?
  • mmbr1606 Profile Picture
    14,605 Super User 2025 Season 2 on at
    you need to check the update property of the datacards and have a look whats in there
     
    cheers
  • Suggested answer
    ronaldwalcott Profile Picture
    3,847 Super User 2025 Season 2 on at
    Should probably be something like
     
    LookUp(
            'Invoice Master',
            ID = Form5.LastSubmit.ID
                )
           
    When you use SubmitForm, LastSubmit() retrieves the last record that was submitted. I am assuming that the Invoice record you want to save is associated with the same person but you haven't provided those details.
  • Seth18 Profile Picture
    146 on at
     
    Your code suggestion is work with just some of adjustment as below:
     
    UpdateContext({SaveButtonPressed: true});
    Set(
        ChangeNumberVar,
        Text(
            Value(DataCardValue22.Text),
            "[$-en-GB]$#,###.00"
        )
    );
    SubmitForm(Form5);
    // Hide buttons or set other UI flags if needed
    Set(
        showFormButtons,
        false
    );
    Patch(
        [@'Invoice Master'],
        Defaults('Invoice Master'),
        Form5.Updates,
        {
            'Request ID': DataCardValue10.Text,
            'Amount': ChangeNumberVar
        }
    );
    Patch(
        [@'Expense Claim Automation'],
        LookUp(
            'Expense Claim Automation',
            Text(ID) = DataCardValue10.Text
        ),
        {
            'Total Amount:': Sum(
                Filter(
                    Gallery3.AllItems,
                    'Request ID' = Text(Gallery2.Selected.ID)
                ),
                Amount
            )
        }
     

     

    but currently it only work when i selected Cash Advance but when i select Expense Claims it occurs a new error in the backend sharepoint of Invoice Master (As the below screenshot) it currently creating duplicate 2 data in which the first one is correct (but missing the request ID) wihle the other have the request ID (but missing the data)
     
     
     
     
     
     
  • mmbr1606 Profile Picture
    14,605 Super User 2025 Season 2 on at
    hey
     
     
     
    can u try this approach:
    UpdateContext({ SaveButtonPressed: true });
    Set(ChangeNumberVar, Text(Value(DataCardValue22.Text), "[$-en-GB]$#,###.00"));
    SubmitForm(Form5);
    If(
        Form5.Valid,
        With(
            {
                requestID: DataCardValue10.Text
            },
            Patch(
                [@'Invoice Master'],
                Defaults('Invoice Master'),
                Form5.Updates,
                {
                    'Request ID': requestID,
                    'Amount': ChangeNumberVar
                }
            ),
            Patch(
                [@'Expense Claim Automation'],
                LookUp('Expense Claim Automation', Text(ID) = requestID),
                {
                    'Total Amount:': Sum(
                        Filter(
                            Gallery3.AllItems,
                            'Request ID' = Text(Gallery2.Selected.ID)
                        ),
                        Amount
                    )
                }
            )
        )
    );
    
    ifd my reply helped, please mark as verified answer
     
     
    cheers
  • Seth18 Profile Picture
    146 on at
     
    I tried your approach but it does not work as well! it only work just how i reply to the other guy
  • Seth18 Profile Picture
    146 on at
    Hi mmbr1606 ,
     
     
    it show like this in the screenshot i've send to you! 

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