Get Autoincrement value on Create/Insert. NAV 2013 R2
delaghetto
Member Posts: 89
I have a requirement:
- We have a table called "Header" with a field "Header No." This is an Autoincrement Integer field.
- We have a table called "Lines", with a field called "Header No." with direct TableRelation to the Header table field.
Now the requirement is that when a new Header is created, we automatically have to create 4 Lines. The problem is that in the OnInsert() trigger of the Header table, we don't have the new Autoincrement value, so we can't fill the Header No. in the Lines.
We will use a Page to create every new header. ¿Any ideas on how we can get the AutoIncrement value, or achieve this with some workaround?
Thanks.
- We have a table called "Header" with a field "Header No." This is an Autoincrement Integer field.
- We have a table called "Lines", with a field called "Header No." with direct TableRelation to the Header table field.
Now the requirement is that when a new Header is created, we automatically have to create 4 Lines. The problem is that in the OnInsert() trigger of the Header table, we don't have the new Autoincrement value, so we can't fill the Header No. in the Lines.
We will use a Page to create every new header. ¿Any ideas on how we can get the AutoIncrement value, or achieve this with some workaround?
Thanks.
0
Comments
-
I wouldn't use AutoIncrement and search in the insert trigger for the last used number, but I guess that is not an option.
You can use the trigger of the page:OnInsertRecord(BelowxRec : Boolean) : Boolean INSERT(TRUE); // Call table trigger // Insert lines here EXIT(FALSE); // Don't insert again
0 -
This seems very similar to the typical header/line page, such as Purchase Orders, Sales Orders, etc. Although the "No." field on these records is of type "Code" rather than Integer, they use the built-in No. Series management functions to increment these numbers, and could be easily converted to integer.
I've also auto-inserted purchase lines into these types of documents. The code can be done in the OnInsert trigger of the "Header" table in most cases, but sometimes needs to be done in the page OnInsert trigger. You have access to the Header's "No." field and thereby can put that reference in the "Line" or "Detail" records as well.Ron0 -
Thanks guys!
INSERT(TRUE) did the trick for us.
Next time I will consider manual autoincrement or Number sequence like in Orders, etc.
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 324 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions