Skip to main content

Notifications

Power Apps - Building Power Apps
Suggested answer

Saving button is not generating the right data

Posted on by 92
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:
  • Seth18 Profile Picture
    Seth18 92 on at
    Saving button is not generating the right data
     
    For the provided code you have given the Expense claim condition work perfectly but again the Cash Advance condition is still the same (it not submitting the form as well)
  • mmbr1606 Profile Picture
    mmbr1606 9,998 on at
    Saving button is not generating the right data
    Hey 
     
    Can u try this:
     
    UpdateContext({SaveButtonPressed: true});
     
    If(
        ComboBoxTypeSelection.Selected.Value = "Expense Claim",
        If(
            !IsBlank(DataCardValue10.Text),
            SubmitForm(Form5);
            Patch(
                [@'Invoice Master'],
                Form5.LastSubmit,
                {
                    'Request ID': DataCardValue10.Text,
                    Amount: ChangeNumberVar
                }
            );
            Patch(
                [@'Expense Claim Automation'],
                LookUp(
                    'Expense Claim Automation',
                    ID = DataCardValue10.Text
                ),
                {
                    'Total Amount': Sum(
                        Filter(
                            Gallery3.AllItems,
                            'Request ID' = Text(Gallery2.Selected.ID)
                        ),
                        Amount
                    )
                }
            )
        ),
        ComboBoxTypeSelection.Selected.Value = "Cash Advance",
        If(
            !IsBlank(DataCardValue10.Text),
            SubmitForm(Form5);
            Patch(
                [@'Invoice Master'],
                Form5.LastSubmit,
                {
                    'Request ID': DataCardValue10.Text,
                    Amount: ChangeNumberVar
                }
            )
        )
    );
     
    Set(showFormButtons, false);
     
     
    If IT helped please mark as verified
     
    Che
  • Seth18 Profile Picture
    Seth18 92 on at
    Saving button is not generating the right data
     
    UpdateContext({SaveButtonPressed: true});
    If(
        !IsBlank(DataCardValue10.Text),
        SubmitForm(Form5);
    );
    If(
        !IsBlank(DataCardValue22.Text),
        Set(
            ChangeNumberVar,
            Text(
                Value(DataCardValue22.Text),
                 "[$-en-GB]$#,###.00"
            )  
        )
    );
    Set(
        showFormButtons,
        false
    );
     
    Patch(
        [@'Invoice Master'],
       //Defaults('Invoice Master'),
       Form5.LastSubmit,
        //Form5.Updates,
        {
            'Request ID': DataCardValue10.Text,
            Amount: ChangeNumberVar
        }
    );
    If(
        !IsBlank(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
                )
            }
        )
    );

    Here is the full code again ( i changed to form5.lastsubmit) it worked until now there some issues. So currently in the homescreen there are 2 types for selection (Cash Advance or Expense Claim). When Expense Claim is selected and move to the invoice screen when clicked save (the code above) it will submit the form and everything work fine. But when the selection is Cash Advance (the code above does not submit any information) and that an issue. 
  • mmbr1606 Profile Picture
    mmbr1606 9,998 on at
    Saving button is not generating the right data
    we can try to modify the code and use a lookup instead of defaults
     
    UpdateContext({ SaveButtonPressed: true });
    Set(ChangeNumberVar, Text(Value(DataCardValue22.Text), "[$-en-GB]$#,###.00"));
    SubmitForm(Form5);
    If(
        Form5.Valid,
        With(
            {
                requestID: DataCardValue10.Text
            },
            Patch(
                [@'Invoice Master'],
                LookUp('Invoice Master', 'Request ID' = requestID),
                {
                    'Amount': ChangeNumberVar,
                    'Request ID': requestID
                }
            ),
            Patch(
                [@'Expense Claim Automation'],
                LookUp('Expense Claim Automation', Text(ID) = requestID),
                {
                    'Total Amount:': Sum(
                        Filter(
                            Gallery3.AllItems,
                            'Request ID' = Text(Gallery2.Selected.ID)
                        ),
                        Amount
                    )
                }
            )
        )
    );
    
     
  • Seth18 Profile Picture
    Seth18 92 on at
    Saving button is not generating the right data
    Hi mmbr1606 ,
     
     
    it show like this in the screenshot i've send to you! 
  • Seth18 Profile Picture
    Seth18 92 on at
    Saving button is not generating the right data
     
    I tried your approach but it does not work as well! it only work just how i reply to the other guy
  • mmbr1606 Profile Picture
    mmbr1606 9,998 on at
    Saving button is not generating the right data
    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
    Seth18 92 on at
    Saving button is not generating the right data
     
    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)
     
     
     
     
     
     
  • Suggested answer
    ronaldwalcott Profile Picture
    ronaldwalcott 1,167 on at
    Saving button is not generating the right data
    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.
  • mmbr1606 Profile Picture
    mmbr1606 9,998 on at
    Saving button is not generating the right data
    you need to check the update property of the datacards and have a look whats in there
     
    cheers

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,591

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,090

Leaderboard