Many people know that when a sales order or purchase order is deleted, it is actually not purged from system like lot of other data but sits in the voided tables. These orders can be viewed from AR -> Inquiries -> History -> Voided sales order or AP -> Inquiries -> History -> Voided Purchase order.
Now from this form you can only view the deleted orders but there is not option of restoring them.
Below are some sample code that can be used to restore the voided orders.
Sales order restoration:
static void restoreDeletedSO(Args _args)
{
SalesTableDelete salesTableDelete;
SalesLineDelete salesLineDelete;
SalesTable salesTable;
SalesLine salesLine;
;
{
SalesTableDelete salesTableDelete;
SalesLineDelete salesLineDelete;
SalesTable salesTable;
SalesLine salesLine;
;
SalesTableDelete = SalesTableDelete::find('00450_036', true);
ttsbegin;
switch (salesTableDelete.Cancelled)
{
case Voided::Voided :
salesTable = conpeek(salesTableDelete.SalesTable, 1);
salesTable.insert();
{
case Voided::Voided :
salesTable = conpeek(salesTableDelete.SalesTable, 1);
salesTable.insert();
while select forupdate salesLineDelete where salesLineDelete.SalesId == salesTableDelete.SalesId
{
salesLine = conpeek(salesLineDelete.SalesLine, 1);
salesLine.insert();
}
salesTableDelete.delete();
break;
{
salesLine = conpeek(salesLineDelete.SalesLine, 1);
salesLine.insert();
}
salesTableDelete.delete();
break;
case Voided::linesVoided :
while select forupdate salesLineDelete where salesLineDelete.SalesId == salesTableDelete.SalesId
{
salesLine = conpeek(salesLineDelete.SalesLine, 1);
salesLine.insert();
salesLineDelete.delete();
}
salesTableDelete.delete();
break;
}
while select forupdate salesLineDelete where salesLineDelete.SalesId == salesTableDelete.SalesId
{
salesLine = conpeek(salesLineDelete.SalesLine, 1);
salesLine.insert();
salesLineDelete.delete();
}
salesTableDelete.delete();
break;
}
ttscommit;
}
}
Purchase order restoration:
static void restoreDeletedPO(Args _args)
{
PurchTableDelete purchTableDelete;
PurchLineDelete purchLineDelete;
PurchTable purchTable;
PurchLine purchLine;
;
{
PurchTableDelete purchTableDelete;
PurchLineDelete purchLineDelete;
PurchTable purchTable;
PurchLine purchLine;
;
purchTableDelete = PurchTableDelete::find('00242_049', true);
ttsbegin;
switch (purchTableDelete.Cancelled)
{
case Voided::Voided :
purchTable = conpeek(purchTableDelete.PurchTable, 1);
purchTable.insert();
{
case Voided::Voided :
purchTable = conpeek(purchTableDelete.PurchTable, 1);
purchTable.insert();
while select forupdate purchLineDelete where purchLineDelete.PurchId == purchTableDelete.PurchId
{
purchLine = conpeek(purchLineDelete.PurchLine, 1);
purchLine.insert();
}
purchTableDelete.delete();
break;
{
purchLine = conpeek(purchLineDelete.PurchLine, 1);
purchLine.insert();
}
purchTableDelete.delete();
break;
case Voided::linesVoided :
while select forupdate purchLineDelete where purchLineDelete.PurchId == purchTableDelete.PurchId
{
purchLine = conpeek(purchLineDelete.PurchLine, 1);
purchLine.insert();
purchLineDelete.delete();
}
purchTableDelete.delete();
break;
}
ttscommit;while select forupdate purchLineDelete where purchLineDelete.PurchId == purchTableDelete.PurchId
{
purchLine = conpeek(purchLineDelete.PurchLine, 1);
purchLine.insert();
purchLineDelete.delete();
}
purchTableDelete.delete();
break;
}
}
cool
ReplyDeleteThank you and I got back the Purchase Order but the ordered quantity was not appear. Any method to solve this?
ReplyDeleteHow about the missign invetory transactions?
ReplyDeleteExactly... this is not advisable at all
DeleteHi,
Deletejust add
salesLine.InventTransId = '';
salesLine.RecId = 0;
before
salesLine.insert();
and InventTrans will be created automatically.
sabun
Great!
ReplyDeletewhere we write this code
ReplyDeleteHi,
DeleteYou can create a Job using X++.
Hi,
ReplyDeleteI've noticed that "xxxxxxLineDelete.delete();" line is missing in "case Voided:Voided". In restoreDeletedPO method as well as in restoreDeletedSO method.
switch (purchTableDelete.Cancelled)
{
case Voided::Voided :
purchTable = conpeek(purchTableDelete.PurchTable, 1);
purchTable.insert();
while select forupdate purchLineDelete where purchLineDelete.PurchId == purchTableDelete.PurchId
{
purchLine = conpeek(purchLineDelete.PurchLine, 1);
purchLine.insert();
purchLineDelete.delete(); <--------------- this line
}
purchTableDelete.delete();
break;
switch (salesTableDelete.Cancelled)
{
case Voided::Voided :
salesTable = conpeek(salesTableDelete.SalesTable, 1);
salesTable.insert();
while select forupdate salesLineDelete where salesLineDelete.SalesId == salesTableDelete.SalesId
{
salesLine = conpeek(salesLineDelete.SalesLine, 1);
salesLine.insert();
salesLineDelete.delete(); <--------------- this line
}
salesTableDelete.delete();
break;