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

Untitled

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!

Untitled

Advertisements

3 thoughts on “AX 2012: Auto increment a field using LineNum

    1. Inserting records by job has a different behavior in AX. What AX does is that it checks whether the lineNum field is initialized or not in the Table.Insert() method e.g. SalesLine.Insert() method. If there is a value, it doesn’t override it but if it is blank then it sets the value based on the standard line numbers logic. For reference, you may see the logic in SaleLine.createLine() method to know how AX sets line numbers.

      Hope this would answer your query!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s