AX 2012: Auto increment a field using LineNum

Do you want a line number field for your table just like we see the line numbers on SalesLine table on the Sales Order? if so then follow the steps below the achieve this functionality.

1. Drag LineNum EDT to the fields node of your table.
2. Create an index on your table and drag the LineNum field to this index
3. While defining the datasource on your form,

  • Set Table to your table
  • Set Index to the index you created which contains the LineNum field
  • Set CounterField to LineNum


4. Override the create() method on your form’s datasource and set the default value of append parameter to be true. This will ensure that records are getting inserted at the bottom so that AX kernel generates positive line numbers instead of negative line numbers because of prepending records at the top!