Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Delete orphan sales order in x++

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

  • Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: Delete orphan sales order in x++

    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.

  • Faran Baig Profile Picture
    Faran Baig 125 on at
    RE: Delete orphan sales order in x++

    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

  • Faran Baig Profile Picture
    Faran Baig 125 on at
    RE: Delete orphan sales order in x++

    I did this,but not worked for me

  • faiz7049 Profile Picture
    faiz7049 1,879 on at
    RE: Delete orphan sales order in x++

    Faran,

    Follow screen shot as given below then execute code.

    2111.jpg

  • Faran Baig Profile Picture
    Faran Baig 125 on at
    RE: Delete orphan sales order in x++

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

  • Faran Baig Profile Picture
    Faran Baig 125 on at
    RE: Delete orphan sales order in x++

    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?

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: Delete orphan sales order in x++

    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
    Faran Baig 125 on at
    RE: Delete orphan sales order in x++

    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?

  • Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: Delete orphan sales order in x++

    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;
    }

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans