I want to reset Line No. when line is deleted, how can I do that?

Vesna_1Vesna_1 Member Posts: 23
I want to reset Line No. when line is deleted, how can I do that?
Can I use OnDelete trigger and how?
When I delete all records and want to create new, Line No. is not starting from 1. It starts from last number of deleted records.

Answers

  • kvbkvb Member Posts: 107
    you can override default "Line No." value (it is incrementing with every new record no matter what)
    Create function:
    GetNewLineNo () : integer 
    lr_SomeRec.SETRANGE("Primary Key Field", Rec."Primary Key Field")
    IF lr_SomeRec.FINDLAST
      THEN EXIT(lr_SomeRec."Line No." + 1)
      ELSE EXIT(0)
    
    Add this code to the last line of the OnInsert trigger of table:
    "Line No." := GetNewLineNo;
    

    not the best practice at all but sometimes we have to do something just nice for customer, aren`t we? :)
  • Vesna_1Vesna_1 Member Posts: 23
    AutoIncrement is set to Yes
  • loggerlogger Member Posts: 126
    Honestly speaking, it is a REALLY BAD IDEA to manually change value in AutoIncrement field. I faced with the similar issue recently, when developer tried to manually set numbers to AutoIncrement field, and we had many troubles with users. In detailed way, you can read http://bpsoftware.com/2012/12/01/microsoft-dynamics-nav-permission-error-set-identity_insert/

    IMHO, as described on the link above, you have 2 options:
    1. Leave AutoIncrement field alone, not trying to change it manually in any way;
    2. Change AutoIncrement Property to false, and manage this field manually.
    Let's go!
Sign In or Register to comment.