Most of the organization need batch jobs in which they want to cancel a purchase order when a particular business event occurs. For this the Technical Consultant can use this code: internal final class PurchasrOrderCancel

{

/// <summary>

/// Class entry point. This runnable class is designed to cancel a purchase order using x++ code

/// </summary>

/// <param name = “_args”>The specified arguments.</param>

public static void main(Args _args)

{

PurchTable purchTable = PurchTable::find(“PO-123”); //enter your purhcase orde here

PurchLine purchLine;

ttsbegin;

while select forupdate * from purchLine

where purchLine.PurchId == purchTable.PurchId && purchLine.IsDeleted == NoYes::No

{

if (purchLine)

{

// Set remaining inventory Qty to zero

purchLine.RemainInventPhysical = 0;

// Set remaining physical Qty to zero

purchLine.RemainPurchPhysical = 0;

// We have to cancel the purchLine

// Not necessary, I did this to do exactly like AX does

purchLine.PurchStatus = PurchStatus::Canceled;

// Update PurchLine

purchLine.update();

// This method will update the inventory transactions

InventMovement::bufferSetRemainQty(purchLine);

}

}

ttscommit;

}

}

Leave a Reply

Your email address will not be published. Required fields are marked *