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

Announcements

No record found.

News and Announcements icon
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 2,025
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"?
  • Suggested answer
    Martin Dráb Profile Picture
    241,423 Most Valuable Professional on at
    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
    2,025 on at
    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
    241,423 Most Valuable Professional on at
    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
    2,025 on at
    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
    241,423 Most Valuable Professional on at
    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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 543 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 387 Super User 2026 Season 2

#3
CU-1234529-002 Profile Picture

CU-1234529-002 185

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans