This post is machine-translated. The original post in german language can be found here.

Post the outgoing invoice by code, selecting only certain order lines and adjusting the quantity if necessary

Using the following code, you can post a sales invoice for a particular sales order and process only selected lines.
The trick is to use the standard functionality of the initLinesQuery() method to create the SalesParmLine table and modify these data records before posting. For example, by deleting entire data records from the SalesParmLine.

static void createSalesInvoiceSelectLines(Args _args)
{
    SalesTable salesTable = SalesTable::find('001562');
    SalesFormLetter salesFormLetter;
    SalesParmLine salesParmLine;
    
    setPrefix(funcName());
    
    salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice);

    // Do the steps manually, which normally are done in method salesFormLetter.update()
    salesFormLetter.salesTable(salesTable);
    salesFormLetter.initParmSalesTable(salesFormLetter.salesTable());
    salesFormLetter.transDate(systemDateGet());
    salesFormLetter.specQty(SalesUpdate::All);
    salesFormLetter.proforma(salesFormLetter.salesParmUpdate().Proforma);
    salesFormLetter.printFormLetter(salesFormLetter.printFormLetter());
    salesFormLetter.printCODLabel(NoYes::No);
    salesFormLetter.printShippingLabel(NoYes::No);
    salesFormLetter.usePrintManagement(false);
    salesFormLetter.creditRemaining(salesFormLetter.creditRemaining());

    salesFormLetter.createParmUpdateFromParmUpdateRecord(
        SalesFormletterParmData::initSalesParmUpdateFormletter(
            salesFormLetter.documentStatus(),                   
            salesFormLetter.pack(),                                                                                                                
            true,                                                                                                                
            false,                                                                                                                
            false));

    salesFormLetter.initParameters(salesFormLetter.salesParmUpdate(), Printout::Current);

    salesFormLetter.initLinesQuery();
    
    while select forupdate salesParmLine
        where salesParmLine.ParmId == salesFormLetter.parmId()
    {
        setPrefix(#PrefixField(salesParmLine, InventTransId));
        
        // ...Modify record/Delete record...
    }

    // Let's go
    if (salesFormLetter.validate(null))
    {
        salesFormLetter.run();
    }
}

 

These post applies to following version:
Dynamics AX 2012

Add comment
 
 
 

 

 
 
 
Posts of the actual month
Juni 2019
MoTuWeThFrSaSu
 12
3456789
10111213141516
17181920212223
24252627282930
 
© 2006-2019 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.