Search code examples
x++ax

Cancel Sales order packing slip through x++


I've been trying to cancel a Sales order packing slip. I'm verifying if it worked by trying to repost but receiving one error after the next.

I have found a way to post a packing slip but is there an easy way to cancel a packing slip without finding all the fields that need to be updated in the inventory movement tables?

Is there something simple like posting (example below):

static void SalesOrderPost(Args _args)
{
    SalesFormLetter salesFormLetter;
    salesTable      salesTable;

    salesTable = SalesTable::find('SO-101248');

    salesFormLetter = SalesFormLetter::construct(
        DocumentStatus::PackingSlip);

    salesFormLetter.update(
        salesTable,
        systemDateGet(),
        SalesUpdate::All,
        AccountOrder::None,
        NoYes::No,
        NoYes::Yes);
}

Solution

  • I was able to retrieve the customer packing slip journal record and pass it to the SalesFormLetter_PackingSlipCancel action menu item.

    CustPackingSlipJour             custPackingSlipJour;
    boolean                         isCancelEnabled, isCorrectionEnabled;
    
    Args                            args;
    
    //find latest packing slip
    select * from custPackingSlipJour
        order by PackingSlipId desc
        where custPackingSlipJour.SalesId == salesTable.SalesId;
    
    [isCancelEnabled, isCorrectionEnabled] = custPackingSlipJour.canPackingSlipBeCanceledOrCorrected();
    
    if(isCancelEnabled)
    {
        //"cancel" latest packing slip
        args = new Args();
        args.record(custPackingSlipJour);
        new MenuFunction(menuitemActionStr(SalesFormLetter_PackingSlipCancel), MenuItemType::Action).run(args);
    }
    
    super();