Customize Purchase order approval status
In the case of D365 Finance and Operations when you approve purchase requisition by default system creates Purchase order with approval status as “Approved” as follows
To change this default behavior of system such that once purchase requisition is approved the approval status of the purchase order as a draft you can use the following class
class CFSPOStatus
{
/// <summary>
///
/// </summary>
/// <param name=”args”></param>
[PostHandlerFor(classStr(PurchAutoCreate_PurchReq), methodStr(PurchAutoCreate_PurchReq, endUpdate))]
public static void PurchAutoCreate_PurchReq_Post_endUpdate(XppPrePostArgs args)
{
//PurchTable purchTable = args.getThis(‘purchTable’);
PurchAutoCreate_PurchReq purchReq = args.getThis() as PurchAutoCreate_PurchReq;
PurchTable purchTable, purchTablenew;
purchTable = purchReq.parmPurchTable();
ttsbegin;
select forupdate purchTablenew where purchTableNew.PurchId == purchTable.PurchId;
if(purchTablenew && purchTablenew.DocumentState == VersioningDocumentState::Approved)
{
purchTablenew.DocumentState = VersioningDocumentState::Draft;
purchTablenew.update();
}
ttscommit;
}
}and your final result looks like
And after changing status you can apply your own purchase order workflow on it.
For purchase order workflow you can refer to my blog
Related posts:
Use Database Access Intent List to Boost Performance in Business Central
Enabling Physical Negative Inventory in Dynamics 365 Finance and Operations
Advance warehouse management – Warehouses and Locations in Microsoft D365 F&O - Part 2
Advance warehouse management – Item Creation process in Microsoft D365 F&O - Part 1