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);
        salesformletterparmData.parmOnlyCreateParmUpdate(true);
        salesformletterparmData.createData(false);
        salesParmUpdate = salesformletterparmData.parmParmUpdate();
        salesParmTable.clear();
        salesParmTable.initFromSalesTable(_salesTable);
        salesParmTable.TransDate             = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone());
        salesParmTable.Ordering              = DocumentStatus::PackingSlip;
        salesParmTable.ParmJobStatus         = ParmJobStatus::Waiting;
        salesParmTable.ParmId                = salesParmUpdate.ParmId;
        salesParmTable.insert();

        while  select  salesLine
        where salesLine.SalesId == _salesTable.SalesId
        {
            salesParmLine.clear();
            salesParmLine.initFromSalesLine(salesLine);
            SalesParmLine.ParmId = salesParmTable.ParmId;
            SalesParmLine.TableRefId = SalesParmTable.TableRefId;
            //I want to deliver all ordered quantity
            SalesParmLine.DeliverNow = salesline.SalesQty;
            SalesParmLine.modifiedDeliverNow();
            SalesParmLine.setQty(DocumentStatus::PackingSlip, false);
            SalesParmLine.setLineAmount();
            SalesParmLine.insert();
        }
        SalesFormLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip);
        SalesFormLetter.parmVersioningUpdateType(VersioningUpdateType::Initial);
        SalesFormLetter.salesParmUpdate(SalesformletterParmData.parmParmUpdate());
        SalesFormLetter.parmCallerTable(_salesTable);
        SalesFormLetter.parmId(salesParmTable.ParmId);
        SalesFormLetter.specQty(SalesUpdate::DeliverNow);
        SalesFormLetter.transDate(DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()));
        SalesFormLetter.proforma(false);
 SalesFormLetter.run();
    }