Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

What is the use of Table Write() method

Posted on by Microsoft Employee

Hi All,

Can somebody explain the use of write method at table level.

Regards,

Nunna

*This post is locked for comments

  • Suggested answer
    Peter Ramer Profile Picture
    Peter Ramer 65 on at
    RE: What is the use of Table Write() method

    I think I can explain where some of the confusion is coming from.

    As stated by others, the 'Write' method on a table will call either insert or update on table, depending on whether the record already has a RecId or not.  That I think is fine, and not where the true question resides.

    I think what is important to note is that unlike the 'write' method on a Form Datasource, the 'write' method on a table does NOT get called by the system when the record is saved.

    So, to say it again, when a user saves a record on a form, the system will call the 'write' method on the Datasource.  And that method will ultimately call either the 'insert' or 'update' method on the table, depending on whether the record is a new record or not.  But, the write method on the table will NOT be called.

    This I think is a bit confusing and different than some other methods.  For example, if you have some additional validation logic, you could put the code in either the 'validateWrite' on the Datasource or the 'validateWrite' on the table.  Both are called by the system.  However, when it comes to the 'write' method, only the Datasource write method is called, and NOT the table 'write' method.

    It would seem that the 'write' method on the table gets called when it is explicitly called through code, and can be useful for this purpose.  But it does not seem to be called by forms.  (Please correct me if I am mistaken).  

    Most of the time when a developer is writing their code, they know whether the record exists or not, so they will either call 'update' or 'insert' directly.  They typically would not call the 'write' method on a table.  Therefore, if you have logic that needs to run when a record is saved, it probably makes sense to create a new method to store this logic.  But then call this logic from both the 'update' and the 'insert' method.  While you could put it in the 'write' method, there is a chance it won't get called if another developer doesn't know it is there and just calls 'update' or 'insert' directly.  Which is common to do.

  • Suggested answer
    Gourav Goyal Profile Picture
    Gourav Goyal 30 on at
    RE: What is the use of Table Write() method

    Write method is used on forms data source to insert or update records to database. The difference is that write calls validatewrite method. Insert method being on the table inserts records into the table. So, in form use Write and in tables use Insert.

    Arun Sharma

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: What is the use of Table Write() method

    Thanks Sohaib for sharing information.

    Regards,

    Nunna

  • Sohaib Cheema Profile Picture
    Sohaib Cheema 46,610 User Group Leader on at
    RE: What is the use of Table Write() method

    read and search about sequence of executions

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: What is the use of Table Write() method

    Thanks Martin for sharing information.

    Regards,

    Nunna

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: What is the use of Table Write() method

    Hi Sohalib,

    Even I too agree with marin, Since it is there in Documentation.

    But Form data source write() method is hitting, then what might be the debugger issue to not hit in table write method.,

    And also I have written info statement in table write method, I didn't info message as well while update/insert. So it's clear that table write() method will not while insetting or updating record, and I just want to know when this method will get execute.

  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: What is the use of Table Write() method

    write() calls insert() or update(), not the other way around.

  • Sohaib Cheema Profile Picture
    Sohaib Cheema 46,610 User Group Leader on at
    RE: What is the use of Table Write() method

    there can be other reasons if debugger is not going there inside.

    what martin told you, is correct.

    msdn.microsoft.com/.../aa569665.aspx

    blaming write() method for 'Debugger not working' is not correct.

  • Suggested answer
    fatihgork Profile Picture
    fatihgork 3,815 on at
    RE: What is the use of Table Write() method

    Hello,

    DMF imports are using it, also thats why DMF is missing validations

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: What is the use of Table Write() method

    Yes it stated same,

    But if I keep the break point in that method, it's not hitting while inserting/ updating.

    Hence I assume, this method will not hit while insert/ update, Can you tell me why debugger is not hitting

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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans