Get Autoincrement value on Create/Insert. NAV 2013 R2

delaghettodelaghetto Member Posts: 89
edited 2014-05-14 in NAV Three Tier
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.

Comments

  • SiStSiSt Member Posts: 46
    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
    
  • rsaritzkyrsaritzky Member Posts: 469
    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.
    Ron
  • delaghettodelaghetto Member Posts: 89
    Thanks guys!

    INSERT(TRUE) did the trick for us.

    Next time I will consider manual autoincrement or Number sequence like in Orders, etc. :lol:
Sign In or Register to comment.