web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

access to invoiced salesLines in x++

(1) ShareShare
ReportReport
Posted on by 1,963
if let's say i invoiced 3 lines out of 5

how can i access one of the salesLines from method "endPost" in class "SalesInvoiceJournalPost"?
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,679 Most Valuable Professional on at
    access to invoiced salesLines in x++
    It would have helped if you mentioned which part you're struggling with.
     
    First of all, realize that you have a reference to the invoice journal in custInvoiceJour variable. Journal lines are in CustInvoiceTrans table; look at its CustInvoiceJour relation to understand how to get lines for a given journal. You might also get the last line by calling journalLine() method.
     
    When you have a CustInvoiceTrans record, call its salesLine() method to get the sales line (or open the method to see what it does and incorporate the logic in your own query).
  • .. Profile Picture
    1,963 on at
    access to invoiced salesLines in x++
    Hi Martin,

    You mean like this:
     CustInvoiceTrans custInvoiceTrans = this.journalLine();
     SalesLine salesLine               = SalesLine::findInventTransId(custInvoiceTrans.InventTransId);
    Or this:
    CustInvoiceTrans custInvoiceTrans;
     select firstonly custInvoiceTrans where custInvoiceTrans.InvoiceId == custInvoiceJour.InvoiceId
         && custInvoiceTrans.SalesId ==  custInvoiceJour.SalesId
         && custInvoiceTrans.InvoiceDate ==  custInvoiceJour.InvoiceDate
         && custInvoiceTrans.numberSequenceGroup ==  custInvoiceJour.numberSequenceGroup;
     
    SalesLine salesLine = SalesLine::findInventTransId(custInvoiceTrans.InventTransId);
     
  • Martin Dráb Profile Picture
    237,679 Most Valuable Professional on at
    access to invoiced salesLines in x++
    Yes, there may be many variants of code like this, depending on what exactly you want to achieve.
     
    It's not a functional problem, but the fact that you duplicated the content of salesLine() method instead of just calling it make the code more complex, i.e. worse (harder to understand and maintain).
  • .. Profile Picture
    1,963 on at
    access to invoiced salesLines in x++
    Hi Martin,

    I think I will go with the second approach because this.JournalLine() didn't return anything, Any idea why?
    and ok I will call the salesLine method instead.

    Quick question please, the reason i want to access salesLine is because i want to send a business event, so if i want to send a custom BE when the invoice is generated, then is it better to place the code in SalesInvoiceJournalPostBase or SalesInvoiceJournalPost which extends the base class? and why? how to know how to choose? as both worked


  • Martin Dráb Profile Picture
    237,679 Most Valuable Professional on at
    access to invoiced salesLines in x++
    As you can see in your own screenshot, there already is a business event for the invoice posting. Having two business events for the same logical event sounds wrong.
     
    If your idea is creating a duplicate business event just to provide a different payload, it's not what you should be doing. The business event tells you that an invoice was posted (which covers your scenario too) and you can use something like OData to fetch all details you need. The payload should be very brief, you basically just need to be able to identify the invoice, that's all.
     
    Regarding journalLine(), I said it might be possible to use it. I don't know whether the value is still populated in endPost() (it is in endPostLine()).

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 683 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 563 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 398 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans