web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Delete orphan sales order in x++

(0) ShareShare
ReportReport
Posted on by 125

Hi everyone,

I have deleted a sale order by x++ job.but the inventory impact is not updating on 'on hand' form.i mean if i the item quantity was 3 at sale order line.

then after deleting sale order.the quantity is still coming on 'On Hand'form with on order 3.someone please guide me.

my query was that

Static void DelsO(Args args)

{
SalesTable saleTable;
SalesLine salesLine;

salesIdBase salesidbase;

select saleTable where
salestable.saleid == 'so-98989'
&& salestable.salesStatus == salesstatus::backorder
&& salestable.Documentsatsu == documenrtstatus::None
if(salestable)
{

salesidbase = salestable.salesid;

delete_from salestable

where salestable.salesid == salesidbase ;

}

}

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    239,029 Most Valuable Professional on at

    This can't be your actual code; it's full of misspelled names, there is a missing semicolon after the select statement and so on. Also, please use the </> button in the rich formatting view to paste source code; it preserves code indentation, making it much easier to read.

    I think you intended to write code like this:

    static void delSO(Args args)
    {
        SalesTable salesTable;
        
        ttsBegin;
        
        select forUpdate salesTable
            where salesTable.SalesId == 'so-98989'
               && salesTable.SalesStatus == SalesStatus::BackOrder
               && salesTable.DocumentStatus == DocumentStatus::None;
               
        if (salesTable && salesTable.validateDelete())
        {
            salesTable.delete();
        }
        
        ttsCommit;
    }
  • Faran Baig Profile Picture
    125 on at

    Thanks Martin.but when i delete SO,it throws an error like this

    "updating has been interrupted because there is an inventory transaction with the status registered"

    issue with InventTrans Table,as i said it is an orphan record,can i delete it with some way through code?

  • Verified answer
    Martin Dráb Profile Picture
    239,029 Most Valuable Professional on at

    I know that the title says "Delete orphan sales order", but unfortunately I don't know what you mean by "orphan sales order". Can you elaborate it, please? If you want to completely delete the order, shouldn't you unregister the quantity first? Or maybe that's all what you want and you don't really care about the sales order.

  • Faran Baig Profile Picture
    125 on at

    Actually orphan are those who does not have  retail sale transactions attached to them but they have an impact on On Hand Quantity of item

    that are present inside that sale order.and how to un-register quantity first by code and then delete that sale order?

  • Faran Baig Profile Picture
    125 on at

    Yes i want to delete it completely and dont know how to un register the quantity first.

  • faiz7049 Profile Picture
    2,430 on at

    Faran,

    Follow screen shot as given below then execute code.

    2111.jpg

  • Faran Baig Profile Picture
    125 on at

    I did this,but not worked for me

  • Faran Baig Profile Picture
    125 on at

    Thanks Martin,during backtracking and seeing table relations,I solved my Problem,first I un register the quantity by changing the "receipt status" and "Status issue" in InventTransTable and then deleted Sale order easily,the screenshot of x++ job is attached with.

    07873.Capture.PNG

  • Martin Dráb Profile Picture
    239,029 Most Valuable Professional on at

    Changing InventTrans value looks like an extremely bad idea to me. It can get your database into an inconsistent state, e.g. when inventory transactions don't match InventSum. I strongly recommend you use appropriate classes instead of just changing some tables directly.

    Try InventUpd_Reservation::updateReserveBuffer() or something like that.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans