• Tag Archives AX7
  • How to choose PackingSlipId for CustPackingSlip by code in AX 365

    The standard AX procedure allows to manually choose the packingslipId just for VendPackingSlipJour.  To choose the packingSlipId for CustPackingSlipJour in AX 365 is not a trivial task, because developers cannot perform overlayering to change the system behaviour.

    Class SalesFormLetter , LetterFormCreate and their subclasses, used by the system to create the custpackingslip,  are very “armored”. I’ve not found any useful hookable method in these classes.

    Reading the code into the classes , i noticed the procedure first gets the sequence number for the packingSlipId , later on it initializes the custpackingslipjour tablebuffer, using the field in relative SalesTable record.

    Then i decided to add a new field in SalesTable Table called “ChoosenPackingSlipId” and to resolve the task using an event handler ad the end of initialization method of CustPackingslipJour. It is the following:

     [PostHandlerFor(tableStr(CustPackingSlipJour),tableMethodStr(CustPackingSlipJour, initFromSalesTable))]
     public static void CustPackingSlipJour_Post_initFromSalesTable(XppPrePostArgs args)
        SalesTable salestable = Args.getArg("_salesTable");
        CustPackingSlipJour CustpackSlipjour = args.getthis();
        CustPackingSlipJour existentCustpackSlipjour;
        select firstonly existentCustpackSlipjour where existentCustpackSlipjour.PackingSlipId == salestable.ChoosenPackingSlipId;
           CustpackSlipjour.PackingSlipId= salestable.ChoosenPackingSlipId;

    So that, when the procedure to create CustPackingSlip is called by code or a user create a Custpackingslip by user side, as result the file custpackingslipId is equal to the field “ChoosenPackingslipId”

  • Post CustPackingSlip in x++ on Dynamics AX 365

    Searching a way to post a CustPackingSlip referred to a sales order by code in AX, i have found a lot of posts that explain how to resolve this task through the following code :

    SalesFormLetter salesFormLetter;
    SalesTable salesTable;
    salesFormLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip);
    salesFormLetter.update(salesTable, systemDateGet(), SalesUpdate::PackingSlip, AccountOrder::None, NoYes::No, NoYes::No, NoYes::No);

    Unfortunately this code seems to be written only for AX 2012 or older version of Ax, because on AX7 it does not work fine.

    Then i’ve found a code written by Muhammad Anas Khan, made to post the VendPackingslips. Following the same staps i’ve write my version to post the CustPackingSlip.

    public static void PostPackingSlip(salesTable _salesTable)
            SalesLine                       salesLine;
            SalesFormLetter salesformletter;
            SalesFormletterParmData salesformletterparmData;
            SalesParmUpdate salesParmUpdate;
            SalesParmTable salesParmTable;
            SalesParmLine salesParmLine;
            salesformletterparmData = SalesFormletterParmData::newData(DocumentStatus::PackingSlip,VersioningUpdateType::Initial);
            salesParmUpdate = salesformletterparmData.parmParmUpdate();
            salesParmTable.TransDate             = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone());
            salesParmTable.Ordering              = DocumentStatus::PackingSlip;
            salesParmTable.ParmJobStatus         = ParmJobStatus::Waiting;
            salesParmTable.ParmId                = salesParmUpdate.ParmId;
            while  select  salesLine
            where salesLine.SalesId == _salesTable.SalesId
                SalesParmLine.ParmId = salesParmTable.ParmId;
                SalesParmLine.TableRefId = SalesParmTable.TableRefId;
                //I want to deliver all ordered quantity
                SalesParmLine.DeliverNow = salesline.SalesQty;
                SalesParmLine.setQty(DocumentStatus::PackingSlip, false);
            SalesFormLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip);