Confirm a cancelled PO in AX2012

There might a situation when you make changes to a cancelled PO and process a confirmation. It is little tricky  since the status would be set to cancelled and editing the values are not possible.
I tried the below job and with that I could confirm a cancelled PO
public static void Ani_CancelConfirmation(PurchId _purchId)
{
PurchTable locpurchTable;
PurchFormLetter purchFormLetter;
PurchFormletterParmData purchFormLetterParmData;
PurchParmUpdate purchParmUpdate;
PurchParmTable purchParmTable;
locPurchTable = PurchTable::find(_purchId);
ttsBegin;
// Create PurchParamUpdate table
purchFormLetterParmData = PurchFormletterParmData::newData(
DocumentStatus::PurchaseOrder,
VersioningUpdateType::Initial);
purchFormLetterParmData.parmOnlyCreateParmUpdate(true);
purchFormLetterParmData.createData(false);
purchParmUpdate = purchFormLetterParmData.parmParmUpdate();
// Set PurchParmTable table
purchParmTable.clear();
purchParmTable.TransDate = SystemDateGet();
purchParmTable.DocumentDate = SystemDateGet();
purchParmTable.Ordering = DocumentStatus::PurchaseOrder;
purchParmTable.ParmJobStatus = ParmJobStatus::Waiting;
purchParmTable.PurchId = locPurchTable.PurchId;
purchParmTable.PurchName = locPurchTable.PurchName;
purchParmTable.DeliveryName = locPurchTable.DeliveryName;
purchParmTable.DeliveryPostalAddress = locPurchTable.DeliveryPostalAddress;
purchParmTable.OrderAccount = locPurchTable.OrderAccount;
purchParmTable.CurrencyCode = locPurchTable.CurrencyCode;
purchParmTable.InvoiceAccount = locPurchTable.InvoiceAccount;
purchParmTable.ParmId = purchParmUpdate.ParmId;
purchParmTable.insert();
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
purchFormLetter.transDate(systemDateGet());
purchFormLetter.proforma(false);
purchFormLetter.specQty(PurchUpdate::All);
purchFormLetter.purchTable(locPurchTable);
// This is the ID we hard code as the product receipt ID, if we do the posting via UI
// user would have the option to manually enter this value
purchFormLetter.parmParmTableNum(purchParmTable.ParmId);
purchFormLetter.parmId(purchParmTable.ParmId);
purchFormLetter.purchParmUpdate(purchFormLetterParmData.parmParmUpdate());
purchFormLetter.run();
ttsCommit;
}

 

 

hApPy P0sTiNg…. 🙂

Advertisements

About AnithaEswaran

Hello all, Thanks for visiting my blog. I started this blog to share my learning with Ax members . Since I am from technical background, most of my posts would be from X++. Thanks to my mentor and my colleague Romain who guided and helped me in learning many new concepts in Ax. This instilled confidence in me to handle and troubleshoot complex issues. Feedback wrt to my blog entries are most welcome …
This entry was posted in Ax2012, Dynamics Ax, X++. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s