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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
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

I have the same question (0)
  • Suggested answer
    huijij Profile Picture
    19,811 on at

    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

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 544 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans