Tuesday, February 13, 2024

Post partial packing slip in D365FO

How to Post a Partial Packing Slip in D365FO and AX 2012

How to Post a Partial Packing Slip in D365FO and AX 2012

Understanding the Code

Below is the X++ code snippet demonstrating how to post a partial packing slip for a sales order:

public void postPartialPackingSlip(SalesId _salesId)
{
    SalesFormLetter_PackingSlip     salesFormLetter_PackingSlip;
    salesFormLetter                 salesFormLetter;
    salesFormletterParmData         salesFormLetterParmData;

    SalesParmTable                  salesParmTable;
    SalesParmLine                   salesParmLine;
    salesLine                       salesLine, salesLineUpd;
    salesParmUpdate                 salesParmUpdate;
    SalesTable                      salestable = SalesTable::find(_salesId, true);
    CustPackingSlipJour             custPackingSlipJour;
    TransDate                       packingSlipDate = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone());
    InventDim                       inventDim;
    InventLocation                  inventLocation;

    ttsbegin;
    salesFormLetterParmData = salesFormletterParmData::newData(DocumentStatus::PackingSlip, VersioningUpdateType::Initial);

    salesFormLetterParmData.parmOnlyCreateParmUpdate(true);
    salesFormLetterParmData.createData(false);
    salesParmUpdate = salesFormLetterParmData.parmParmUpdate();

    salesParmTable.clear();
    salesParmTable.TransDate                = PackingSlipDate;
    salesParmTable.Ordering                 = DocumentStatus::PackingSlip;
    salesParmTable.ParmJobStatus            = ParmJobStatus::Waiting;
    salesParmTable.salesId                  = salesTable.salesId;

    salesParmTable.salesName                = salesTable.salesName;
    salesParmTable.DeliveryName             = salesTable.DeliveryName;
    salesParmTable.DeliveryPostalAddress    = salesTable.DeliveryPostalAddress;
    salesParmTable.CustAccount              = salesTable.CustAccount;
    salesParmTable.CurrencyCode             = salesTable.CurrencyCode;
    salesParmTable.InvoiceAccount           = salesTable.InvoiceAccount;
    salesParmTable.ParmId                   = salesParmUpdate.ParmId;
    salesParmTable.insert();

    while select salesLine 
        where salesLine.SalesId == salestable.SalesId
            Join InventDim 
            where inventdim.inventDimId == salesLine.InventDimId
                join inventLocation 
                where inventlocation.InventLocationId == inventdim.InventLocationId
                && inventlocation.TestOwnWareHouse == NoYes::Yes
    {
  
        salesParmLine.InitFromsalesLine(salesLine);
        salesParmLine.DeliverNow    = salesLine.SalesQty;
        salesParmLine.ParmId        = salesParmTable.ParmId;
        salesParmLine.TableRefId    = salesParmTable.TableRefId;
        salesParmLine.setQty(DocumentStatus::PackingSlip, false, true);
        salesParmLine.setLineAmount(salesLine);
        salesParmLine.insert();
    }

    salesFormLetter_PackingSlip = salesFormLetter::construct(DocumentStatus::PackingSlip);
    salesFormLetter_PackingSlip.transDate(PackingSlipDate);
    salesFormLetter_PackingSlip.proforma(false);
    salesFormLetter_PackingSlip.specQty(salesUpdate::All);
    salesFormLetter_PackingSlip.salesTable(salesTable);
    salesFormLetter_PackingSlip.parmId(salesParmTable.ParmId);
    salesFormLetter_PackingSlip.salesParmUpdate(salesFormLetterParmData.parmParmUpdate());
    salesFormLetter_PackingSlip.run();
       
    if (salesFormLetter_PackingSlip.parmJournalRecord().TableId == tableNum(custPackingSlipJour))
    {
        custPackingSlipJour = salesFormLetter_PackingSlip.parmJournalRecord();
        info(custPackingSlipJour.packingSlipId)
    }
    ttscommit;
    
}

Steps to Post a Partial Packing Slip

  1. Initialization: The process begins by initializing necessary variables and objects, such as salesFormLetter_PackingSlip and salesParmUpdate.
  2. Creating Sales Parameters: Sales parameters are populated with relevant data from the sales order, such as customer details, delivery information, and currency.
  3. Handling Sales Lines: Iterate through sales lines associated with the sales order. For each line, initialize a salesParmLine object and set relevant parameters. Ensure the line is associated with a warehouse (TestOwnWareHouse == NoYes::Yes) before proceeding.
  4. Generating the Packing Slip: Use the salesFormLetter_PackingSlip object to generate the packing slip. Set parameters such as transaction date and sales table details. Finally, execute the packing slip generation process.
  5. Verifying the Packing Slip: After generating the packing slip, verify if the process was successful by checking the parmJournalRecord. If successful, retrieve relevant information such as the packing slip ID.

Conclusion

Automating the creation and posting of packing slips, including partial packing slips, streamlines the order fulfillment process in D365FO and AX 2012. By leveraging X++ code, businesses can ensure accuracy and efficiency in their shipping operations.

No comments:

Post a Comment

How to Post Partial Product Receipt in D365FO Using X++ Code

How to Post Partial Product Receipt in D365FO Using X++ Code How to Post Partial Product Receipt in D365FO Using X++...