AX 2012: Cancel product receipt journal in X++

Purpose:

The purpose of this document is to illustrate how we can cancel a posted product receipt in X++.

Business requirement:

Ability to cancel product receipt journal automatically. As of now Standard AX offers manual product receipt cancellation by clicking Procurement and sourcing > Inquiries > Journals > Product receipt > Cancel.

Assumptions:

Product receipt is posted.

Development:

Please find below the job to correct product receipt journal in X++:

// Developed on 28 Dec 2015 by Muhammad Anas Khan
// Blog: dynamicsaxinsight.wordpress.com
// LinkedIn: pk.linkedin.com/in/muhammadanaskhan
// Description: Ability to cancel product receipt journal
static void makPurchPackingSlipCancel(Args _args)
{
    PurchTable           purchTable = PurchTable::find("0000-000187");
    VendPackingSlipJour  vendPackingSlipJour;
    PurchFormLetter      purchFormLetter;

    //Retrieve existing vend packingslip
    select firstOnly vendPackingSlipJour
    where vendPackingSlipJour.PackingSlipId == "MAK3101";

    purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);

    //If the correct VersioningUpdateType is not set
    //the system will try to create a new packingslip
    PurchFormLetter.parmVersioningUpdateType(VersioningUpdateType::Cancel);
    PurchFormLetter.parmCallerTable(vendPackingSlipJour);

    //The rows bellow are very important. Not really sure why
    PurchFormLetter.allowEmptyTable(true);
    PurchFormLetter.initAllowEmptyTable(true);
    PurchFormLetter.multiForm(true);
    purchFormLetter.update( purchTable,     // Purchase record buffer
        vendPackingSlipJour.PackingSlipId,  // Packingslip Number
        VendPackingSlipJour.DeliveryDate,   // Transaction Date
        PurchUpdate::ReceiveNow,            // Quantity update
        AccountOrder::None,
        NoYes::No,
        NoYes::No,
        NoYes::Yes);
}

Testing:

After running the job, you can see below the canceled product receipt journal:

Untitled

After comparing the last 2 product receipt journal versions:

Untitled

Advertisements