Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

Deleting a record from ProdTable programatically by X++

Posted on by Microsoft Employee

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.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee 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
    nmaenpaa 101,148 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
    Faisal Fareed 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
    Community Member Microsoft Employee 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
    Community Member Microsoft Employee 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
    Vilmos Kintera 46,147 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
    nmaenpaa 101,148 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.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,995 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,610 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans