Freigeben über


Best Practices for Table Methods

Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

Following are the types of table methods:

  • Application-defined methods – created by a developer specifically for a particular table.

  • System-defined methods – automatically available on every table. These methods are from the xRecord system class.

Application-Defined Methods

Use the properties available on tables and table fields rather than creating code for the same purpose. If you do need to create a method on a table, it must be directly related to that table.

By default, these methods run on both the client and the server. You can state this explicitly in the method declaration (client server), but don't specify a single tier (client or server). It is a best practice to create these methods on tables. A best practices error does not occur if the method is not called.

System-Defined Methods

System-defined method

Rules

clear

Called by the kernel—you do not need to call this method from the application.

delete

Secure any related transactions.

If you have DeleteActions on one table set to Cascade delete on another table, avoid writing code on the delete method on the second table (for performance reasons).

If you don't add code here, the database management system can quickly do cascading deletes by using direct SQL deletes (DELETE_FROM).

If you do add code here, the system creates a while select statement, and then executes the delete method on all child tables. Warning icon

If you are deleting from the buffer, use skipDelete.

doInsert, doUpdate, doDelete

Avoid using these methods.

These methods should only be used under strict control because they bypass the following:

  • Any validations that have been set up.

  • Any code that was written in the insert, update, and delete methods.

helpField

When manipulating an array, use the standard methods on the Global application class as follows:

  • fieldExt2Id

  • fieldId2Ext

  • fieldExt2Id

For more information about the field ID of an array, see Extended Field IDs.

initValue

The call to super() assigns the default values that you have set by using the record template.

Use the method to assign initial/default values to a new record.

insert

Secure any related transactions with tts.

If insert is overridden, array inserts reverts to record-by-record insert.

isFormDataSource

Called by the kernel—you do not need to call this method from the application.

merge

Called by the kernel—you do not need to call this method from the application.

modifiedField

Called by the kernel—you do not need to call this method from the application.

postLoad

Avoid placing any code here. Instead, use display methods.

The postLoad method is called every time a record is fetched from the database. Avoid creating any code on this method that will have an impact on performance. For example, avoid adding code that involves calls between the client and server, or any code that results in a database operation.

reRead

Called by the kernel—you don't need to call this method from the application.

toolTipField

When manipulating an array, use the standard methods on the Global application class as follows:

  • fieldExt2Id

  • fieldId2Ext

  • fieldExt2Id

For more information about the field ID of an array, see Extended Field IDs.

toolTipRecord

Enables you to append additional information to the standard tooltip text. For example, use the toolTipRecord method to include a message to display a "customer out of credit" message.

update

Secure any related transactions with tts.

If update is overridden, array inserts cannot be used, and automatically reverts to record-by-record insert.

validateDelete

Do not delete the super() call if you override this method.

The method should return a Boolean—don't throw an exception here.

validateField

You should respect the task performed by the super() call.

The method should return a Boolean—don't throw an exception here.

When manipulating an array, use the standard methods on the Global application class as follows:

  • fieldExt2Id

  • fieldId2Ext

  • fieldExt2Id

For more information about the field ID of an array, see Extended Field IDs.

validateWrite

Respect the task performed by the super() call.

The method should return a Boolean. Don't throw an exception here.

xml

Called by the kernel—you don't need to call this method from the application.

See also

Table Methods

Best Practices for Methods

Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.