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 / Update Invoice Parent ...
Power Apps
Unanswered

Update Invoice Parent with sum of all child InvoiceDetails values (via Dataverse Accelerator App)

(0) ShareShare
ReportReport
Posted on by 6

I would like to update fields in the "Invoices" table every time an child InvoicesDetail (aka Invoice Products) record is created, updated or deleted (e.g. the Sum of all Invoice Products privates or tax).

 

It's about the default Invoices + InvoiceProducts table (one Invoice can have n InvoiceProducts).

 

The goal is to solve this via Dataverse Accelerator App.

 

I am not ending up with the correct values, however and I can't figure out how to properly use the "Filter" function in this case: 

 

Patch(
Invoices,
ThisRecord.'Invoice ID',
{
'Total Net Amount': Sum(
Filter(
'Invoice Products',
'Invoice ID'.Invoice = GUID(ThisRecord.invoiceid.'Invoice ID')
),
'Net net'
)
}
)

 

 

How to reference all children of the Invoice (referenced by the Invoice property of the currently updates/modified/deleted/created InvoiceDetails item)?

I have the same question (0)
  • EricRegnier Profile Picture
    8,720 Most Valuable Professional on at

    Hi @funkymusic,

    A couple of notes/questions to consider:

    1. Reference the tables (or other tables) inside plugins with the @[] E.g. @['Invoice Products']
    2. There shouldn't be a new to cast to GUID, you're referencing ThisRecord.'Invoice ID' in the Patch so can't you use directly this inside the Filter?

    Hope this helps...

  • funkymusic Profile Picture
    6 on at

    hi @EricRegnier, thank you for your reply.

     

    - Using the @ Notation does not work:

    Screenshot 2023-11-10 at 18.25.07.png

     

    - Using the ThisRecord.'Invoice ID' does not work:

     

    Screenshot 2023-11-10 at 18.26.32.png

     

    This is the database structure (default invoices table):

    "Invoice ID" / "invoiceid" is a field in the invoicedetails table referencing the parent invoice via lookup field.
    Screenshot 2023-11-10 at 17.37.22.png

     

    As a cross-check, manually filtering for invoicesdetail columns with a static GUI works (parent record will be updated correctly):

    Screenshot 2023-11-10 at 18.29.32.png

    I tried to set a static variable with the value of the parent invoice ID first (as I think the ThisRecord will match the current record in the loop and not the original record firing the event?), but it looks like setting a new variable is not allowed - https://learn.microsoft.com/en-us/power-apps/maker/data-platform/low-code-plug-ins-powerfx ("Requires the variable to exist (as bound table row property) and the variable type to match what you’re trying to set it to.")

  • Verified answer
    EricRegnier Profile Picture
    8,720 Most Valuable Professional on at

    Hi @funkymusic, not sure if you resolved yet but I finally had the chance to test from my side and get what you're saying 🙂 To resolve the main issue with ThisRecord because it's getting referenced within the Filter and so is another context/scope, use the With function. Here's an example. Also noticed how I used the [@] notation that is still required, so not sure why is wasn't working for you:

    With({ invoiceRecord: ThisRecord },
     Patch(Invoices, invoiceRecord, {
     'New Amount': Sum(Filter([@'Invoice Products'], 'Invoice ID'.Invoice = invoiceRecord.Invoice), Amount)
     })
    )

     Hope this help!

  • funkymusic Profile Picture
    6 on at

    @EricRegnier thank you, works like a charm 🙂 Not sure why but I had to add 'Invoice ID' to the With statement but otherwise it works now as expected 🙂

    With({ invoiceRecord: ThisRecord.'Invoice ID' }, 
     Patch(Invoices, invoiceRecord, {
     'Total Net Amount': Sum(Filter([@'Invoice Products'], 'Invoice ID'.Invoice = invoiceRecord.Invoice), 'Net net')
     });
    );

     

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 840 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 332 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 275

Last 30 days Overall leaderboard