Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

How to do sales order invoice through packing slip in x++

(0) ShareShare
ReportReport
Posted on by 97

class TestClass
{
    public static void main(Args _args)
    {
        SalesFormLetter         salesFormLetter;
        SalesTable              salesTable;
        CustPackingSlipJour     custPackingSlipJour;
        CustPackingSlipTrans    custPackingSlipTrans;
        TmpFrmVirtual           tmpFrmVirtual;
        List                    selectedList = new List(Types::Record);
        SalesFormLetter_Invoice     salesFormLetter_Invoice;
        SalesFormLetter     letter      = SalesFormLetter::construct(DocumentStatus::Invoice);
        CustInvoiceTrans    custInvoiceTrans,custinvoicetransupdate;
        SalesParmLine       salesParmLine;
        SalesParmUpdate     salesParmUpdate;
        SalesLine           salesLineLocal;
       // SalesTable salestable;
        CustInvoiceJour custInvoiceJourNew,custinvoicejourupdate;
        ITCommercialInvoiceLine iTCommercialInvoiceLine,iTCommercialInvoiceLineloc,iTCommercialInvoiceLineCheck,iTCommercialInvoiceLineUpdate;
        //boolean             ret = true;
        ITCommercialOverview iTCommercialOverview,iTCommercialOverviewupdate;
        
        tmpFrmVirtual.setTmp();
        RecId recid =  _args.record().RecId;
        // Add the desired packing slips into tmpFrmVirtual
        select iTCommercialOverview
            where iTCommercialOverview.RecId == recid;
        while select salesTable
       // group by SalesId
        where salesTable.SalesId  == iTCommercialOverview.SalesId
        join custPackingSlipTrans
           // group by PackingSlipId //, DeliveryDate
            where custPackingSlipTrans.SalesId  == iTCommercialOverview.SalesId
            && custPackingSlipTrans.CommercialInvoice == iTCommercialOverview.CommercialInvoice
        {
            select  custPackingSlipJour
                where custPackingSlipJour.PackingSlipId == custPackingSlipTrans.PackingSlipId;
             //  && custPackingSlipJour.DeliveryDate  == custPackingSlipTrans.DeliveryDate;
        
            tmpFrmVirtual.clear();
            tmpFrmVirtual.TableNum      = custPackingSlipJour.TableId;
            tmpFrmVirtual.RecordNo      = custPackingSlipJour.RecId;
            tmpFrmVirtual.NoYes         = NoYes::Yes;
            tmpFrmVirtual.Id            = custPackingSlipJour.SalesId;
            tmpFrmVirtual.insert();
        }
    
        while select tmpFrmVirtual
        {
            selectedList.addEnd(tmpFrmVirtual);
        }
    
        // Construct form letter
        salesFormLetter = salesFormLetter::construct(DocumentStatus::Invoice);
        // Add the packing slips to the sales form letter
        salesFormLetter.selectFromJournal(selectedList.pack());
        
        // Reorganize as desired
        salesFormLetter.sumBy(AccountOrder::Account);
        salesFormLetter.reArrangeNow(true);
        salesFormLetter.reArrange();
        salesFormLetter.specQty(SalesUpdate::PackingSlip);

        // Execute
        salesFormLetter.run();

        custInvoiceJourNew = salesFormLetter.parmJournalRecord();
        while select forupdate custinvoicetransupdate
                            where custinvoicetransupdate.SalesId == custInvoiceJourNew.SalesId
                            && custinvoicetransupdate.InvoiceId == custInvoiceJourNew.InvoiceId
        {
            custinvoicetransupdate.CommercialInvoice = iTCommercialOverview.CommercialInvoice;
            custinvoicetransupdate.CommercialDate = iTCommercialOverview.InvoiceDate;
            custinvoicetransupdate.update();
        }
        select forupdate custinvoicejourupdate
                            where custinvoicejourupdate.InvoiceId == custInvoiceJourNew.InvoiceId;
        custinvoicejourupdate.CommercialInvoice = iTCommercialOverview.CommercialInvoice;
        custinvoicejourupdate.CommercialDate = iTCommercialOverview.InvoiceDate;
        custinvoicejourupdate.update();

        select forupdate iTCommercialOverviewupdate
                                    where iTCommercialOverviewupdate.CommercialInvoice == iTCommercialOverview.CommercialInvoice;
        iTCommercialOverviewupdate.Status = ITCommercialInvoiceStatus::Invoiced;
        iTCommercialOverviewupdate.InvoiceNo = custInvoiceJourNew.InvoiceId;
        iTCommercialOverviewupdate.InvoiceDate1=custInvoiceJourNew.InvoiceDate;
                               
        iTCommercialOverviewupdate.update();
        info(strfmt("sales order- %1 posted with invoice Id %2",custInvoiceJourNew.SalesId, custInvoiceJourNew.InvoiceId ));
                 
        while select forupdate iTCommercialInvoiceLineUpdate
                                where iTCommercialInvoiceLineUpdate.CommercialInvoice ==iTCommercialOverview.CommercialInvoice

        {
            select  custinvoicetransupdate
                                 where custinvoicetransupdate.SalesId == iTCommercialInvoiceLineUpdate.SalesId
                                 && custinvoicetransupdate.ItemId == iTCommercialInvoiceLineUpdate.ItemId
                                    && custinvoicetransupdate.InvoiceId == custInvoiceJourNew.InvoiceId;
            iTCommercialInvoiceLineUpdate.InvoicedQty = custinvoicetransupdate.Qty;
            iTCommercialInvoiceLineUpdate.update();
        }
        ttscommit;


    FormDataSource fds;
    Object calleform;
    calleform = _args.caller();

    fds = _args.record().datasource();
    if(calleform)
    {
        fds.refresh();
        fds.research(true);
    }
}

    }

Hi All,

I am using this code to do invoice through packing slip.But i am not able to get value from 
custInvoiceJourNew = salesFormLetter.parmJournalRecord();

Am i missing anything in code.Can anyone pls help me on this.

Thanks in advance

  • Suggested answer
    huijij Profile Picture
    huijij 19,811 on at
    RE: How to do sales order invoice through packing slip in x++

    Hi PJ,

    Do you mean to say that the custInvoiceJourNew value of this code custInvoiceJourNew = salesFormLetter.parmJournalRecord() is empty? Did you check the code example in this old thread?

    community.dynamics.com/.../invoice-sales-order-while-doing-packing-slip-through-code-of-x

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,074 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,900 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans