Monday, 30 November 2015

Serial number field:

In this post I want to share ‘CounterField’ property details that could help you generate counter field or serial number field. At times, you may don’t need a number sequence for the field to generate serial numbers. For those situations this property may come handy.Let’s understand it step by step.

Note: I will be taking the names of the application objects to try to be meaningful. You take your own.

Step 1:

Create a Table CounterField_Test

CF_01
Step 2:Create a Real EDT with No of Decimals set to 0.
CF_02
Step 3:Drag and drop the above EDT in the CounterField_Test and rename the field as ‘Counter’.
CF_03
Step 4:Create an index using ‘Counter’ field of the table and save all.
CF_04
Step 5:Create a form and add CounterField_Test as the datasource for the form. Now, in the properties window of the datasource, select ‘Counter’ in the ‘CounterField’ property.

CF_05
Step 6:Add, Create override method to the datasource and rewrite the below code into it.
public void create(boolean _append = True) // Actual default value is false. Setting True as the default values will allow you to generate positive values forward.
{
    super(_append);
}
Step 7:Expand design node of the form and create a grid and drag the ‘counter’ field of the datasource to the grid and that’s it.
CF_07

Now, if you open the form and add a new row, it will give the incremental numbers by 1 for each row.

No comments:

Post a Comment