SalesFormLetter_Invoice Generate 2 invoices

Hi there, I’m novice in AX. So I want to ask something (easy for you).

I have a new Field in CustParameter table called CustPostingProfile, and a NoYes Field called AG.

In the InventTable I have another NoYes Field called AG, too.

I go to SalesTable, create a new sale with lines:

  1. An article (from InventTable) with AG field unchecked.
  2. An article (from InventTable) with AG checked.

So, I selected Posting > Invoice

When I register an invoice, the system must check in CustParameter if AG field is checked (YES). In this case, the system must generate two diferent invoices, one of them with all lines related to AG articles (AG checked in InventTable). After that the system must generate another invoice related to NO AG articles. Generate ledgerVoucher for each invoice.

I’m using the SalesFormLetter_Invoice class, can generate two invoices but never generates de ledgerVoucher and salesTotals is wrong.

How can I achieve my goal?

Thanks in advance.