How to auto-populate Line-Numbers when creating a new line in D365 F&O?
Scenario: After creating a record, The Line Number field should automatically populate with values when creating a new line.
High Resolution steps
- Write logic in initValue() Method of Form datasource level.
- Test and Validate the Functionality.
Detailed Resolution steps
Step 1: override the initValue() method in the form data source level.
By override the initValue() method in the form data source level, you can automatically populate values when creating a new line by writing the logic for creating Line Number in Sequence.
Code Snippet:
Code:
[DataSource]
class ANKJobLineTable
{
///
/// get line number generated for the field Line Num
///
public void initValue()
{
super();
aNKJobLineTable linetab = this.cursor();
aNKJobLineTable ankJobLineTable1;
select firstonly ankJobLineTable1 order by ankJobLineTable1.LineNum desc where ankJobLineTable1.JobId == linetab.JobId;
linetab.LineNum = ankJobLineTable1.LineNum + 1;
}
Step 2: Test and validate that the line numbers are being automatically populated correctly in the UI. Ensure that when a new line is created, the line number field is populated with the expected value based on the logic implemented and verify that the value updates dynamically as intended within the user interface.
OUTPUT
Below are the results, after creating the record where you can see that the Line-Num field is being auto-populated at the line level.