Hello,
I am trying to delete an address in ax 2012 through code, i am trying to find the addresses which doesn't have any open orders and delete them. All i get is AOS validation error. I debugged the entire process of deletion and found its checking 114 tables for record reference before deletion. Is there a way to delete this kind of addresses. i also tried to expire the address and delete them but failed to do so. Please let me know if we can do this
static void NK_AddressCleanUp(Args _args)
{
LogisticsLocation location;
SalesLine salesLine;
LogisticsPostalAddress logisticsPostalAddress;
utcDateTime toDate = DateTimeUtil::newDateTime(mkDate(4, 5, 2015),0);
ttsBegin;
while select forupdate location
where location.createdDateTime >= toDate && location.createdDateTime <= DateTimeUtil::newDateTime(mkDate(4, 5, 2015), 72000)
join forUpdate logisticsPostalAddress
where logisticsPostalAddress.Location == location.RecId
{
select RecId, SalesId from salesLine where salesline.DeliveryPostalAddress == logisticsPostalAddress.RecId && salesline.SalesStatus != SalesStatus::Invoiced;
if(salesLine.RecId == 0 && location.validateDelete())
{
info(strFmt("%1--%2--%3", location.Description, location.RecId, salesLine.SalesId));
location.Delete();
}
}
ttsCommit;
}