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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How do I Delete a Product/Item programatically in X++

(0) ShareShare
ReportReport
Posted on by

Hey all, my first post on here!

I was tasked with having to delete a lot of obsolete products from AX.  I'm still relatively new to AX.

I'm trying to figure out what code I need to delete a product from our system.  I was told that to manually do it you go into the "Released Products" Page and delete from  there, THEN go to the "Products" Page and delete from there.

I need to do this programatically because I have an Excel file that I'm reading from that has thousands of products listed.  I've already figured out how to read from the an Excel file in X++.

If I look at the method that is being called on those delete buttons, its just "DeleteRecord".  What does that mean?  I can't find that code anywhere?

Any help would be greatly appreciated.  Thanks!

------------------------------
Pedro Coelho
Holman Parts Distribution
Pennsauken NJ
------------------------------

*This post is locked for comments

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    300,896 Super User 2025 Season 2 on at

    Hi Pedro,

    Note that if the items do have transactions or other linked records, you cannot delete them. If they don't have related transactions, you can use the next coding:

    ttsbegin;

    while [Excel loop]

    {

       select forupdate inventTable where inventTable.ItemId == [itemId variable from excel].;

       inventTable.delete();

    }

    ttscommit;

    The table name of the product is called EcoResProduct. Probably you also have to delete some other related tables first if there is no cascade delete action setup on the tables itself for both InventTable and EcoResProduct.

    Thousands of product could take a while using this method.

  • Community Member Profile Picture
    on at

    Would you consider doing it this way part of base AX functionality?

    Also, what tables should I check to make sure that the delete worked correctly?  InventTable, EcoResProduct, etc.  Anywhere else?

    Thank you for your help, I actually wrote this exact code myself but wasn't sure if it was correct!

  • Community Member Profile Picture
    on at

    Additionally, my concern is that doing it this way, I dont receive any warning messages about what I'm deleting like I do using the UI.  It seems like your suggested delete method is different than doing it through the UI.  Do you agree?

  • Mea_ Profile Picture
    60,284 on at

    Hi Pedro Coelho,

    When you click delete button on a Form AX call validateDelete method on form data source. In super() of form data source validateDelete  AX will call validateDelete on a table.

    If validateDelete return true AX call delete of the form data source. In super() of the form data source delete  AX will call delete on the table.

    So calling delete directly from a table you will skip all the Form logic and in 99% of cases it's ok.

  • Community Member Profile Picture
    on at

    Thanks for all your help guys! :)

  • André Arnaud de Calavon Profile Picture
    300,896 Super User 2025 Season 2 on at

    Hi Pedro,

    Would you mind mark one or more answers which helped you? Then the thread will get the status answered.

  • Suggested answer
    Community Member Profile Picture
    on at

    Thanks guys!

  • Community Member Profile Picture
    on at

    Hey guys, so it seems like the delete method (inventTable.delete) is not completely deleting the item from the system.  There are still remnants of the item in the EcoResProduct and EcoResProductIdentifier tables.

    When I delete the product manually using the AX interface (delete button), it seems to completely delete the item from the system, including the table mentioned above.

    Any idea on how to do this programatically?

  • Community Member Profile Picture
    on at

    On a side note, I noticed that in AX, in order to delete a product, I have to delete it first from Released Products before I can delete it from All Products.

    Could this be the missing step I'm looking for programatically?

  • André Arnaud de Calavon Profile Picture
    300,896 Super User 2025 Season 2 on at

    Hi Pedro,

    The All products is a global list of products for all legal entities (EcoResProduct). The released products are the items per company (InventTable). This has a reference to the global product to enable e.g. intercompany orders.

    Programatically you first have to delete the released product. This will not delete the global products. So you have to add logic to also delete the global product.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans