Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Deleting a record from ProdTable programatically by X++

(0) ShareShare
ReportReport
Posted on by

Hi community,

I would like to delete a record from ProdTable (Production Order table) and all of related information from other tables (if any).

The normal way is: open "All production orders" record list, chose a record then press Delete button. The record is deleted well without any error message. Follow this way, after deleting I went to "View >> Net requirement >> Overview Tab" and saw that the associated record is also deleted.

However by doing this programatically, after deleting record from ProdTable, when going to "View >> Net requirement >> Overview Tab" I saw that the associated record still be there. Source code for deleting is:

ProdTable.doDelete();

So my understanding is when Delete button is pressed, the record from ProdTable is deleted and all of other related record from other tables are deleted as well. I looked at the method that is being called on Delete button and saw that is "Delete Record" (command). But unfortunately I can't find where this method is defined.

Is my understanding correct? If yes, where could I find the definition of "Delete Record" command? If not, how could I delete a record from ProdTable correctly? Please help.

Any help would be appreciated. Thank you all.

Wall-e.

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Deleting a record from ProdTable programatically by X++

    Thank all for your help.

    As my investigation so far, when using prodTable.delete() all of related records in other tables will be deleted as well. Other tables could be declared in DeleteAction node with properties "cascade".

    According to my issue, the record in reqTrans was not deleted because the record in prodTable was not deleted successfully. In prodTable, only records with status "Created" could be deleted. If the current status is not Created, it must be reset to Created before perform delete action.

    After I added  a processing of reset status, then the record in ReqTrans table was deleted successfully. In fact, the code should be as:

    - reset status of prodTable record to Created

    - ProdTable.delete()

    Again, thank you all for your support.

  • Suggested answer
    nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: Deleting a record from ProdTable programatically by X++

    I tested this. I created a production order. View -> Net requirements showed records. In ReqTrans, a record was created where RefId was referring to my new ProdId.

    I deleted the production order from the user interface with Delete button. Then I checked ReqTrans with table browser. The requirement record was still there. So it seems that it's not deleted in either case. So the x++ code is working identically with the process that was started from the user interface.

    I think that rerunning Master Planning (for that item) will anyway refresh ReqTrans and clean such leftover rows. But I'm a technical person, not a production / master planning specialist so I might not be 100% correct. At least for me running MP for that item cleaned the orphan entry from ReqTrans.

  • Verified answer
    Faisal Fareed Profile Picture
    10,794 User Group Leader on at
    RE: Deleting a record from ProdTable programatically by X++

    In prodTable check the delete actions node is there any delete action defined for reqTrans table. Delete actions works in three different ways so if its set to cascade then deleting the record from prodTable will also delete corresponding record from reqTrans table. You can check more about delete actions from msdn.

    I am not in front of computer otherwise I could conform this.

  • Community Member Profile Picture
    on at
    RE: Deleting a record from ProdTable programatically by X++

    Thank you all for your help.

    I have followed Nikolaos's suggestion but unfortunately the problem still be there. Taking a look into this method, it just deletes the record from ProdTable and from PmfProdCoby table. That's all.

    Further step in my investigation, the data shown on "Net Requirement" screen is stored in ReqTrans table. But I didn't find any method (of ProdTable) where ReqTrans record is deleted when ProdTable is deleted. So I think there's would be somewhere they defined the Business Logic processing for deleting a record from ProdTable.

    DeleteCommand.png

    Do you all have any idea about button Command "Delete Record"? Where could I find the definition for this?

    Thank you.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Deleting a record from ProdTable programatically by X++

    Hi wall-e ,

      Please look in to below link,

      https://msdn.microsoft.com/en-us/library/aa624886.aspx

    Thanks

    Suresh

  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: Deleting a record from ProdTable programatically by X++

    Definition of doDelete on MSDN:

    msdn.microsoft.com/.../aa628085.aspx

    And as suggested above, use delete() unless you want to ignore the business logic in there, which probably takes care of what you were missing.

  • Verified answer
    nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: Deleting a record from ProdTable programatically by X++

    You should use

    prodTable.delete() instead of prodTable.doDelete().

    If you call doDelete() it will skip all the code that exists in the delete() method.

    Calling the delete() method corresponds to clicking the Delete button on the user interface. In addition to that, in some cases there might be some additional code in the ProdTable form data source, so you could check that as well.

    But most likely calling delete() method will do the trick for you.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,069 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,858 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans