Increment Entry No

SugeevishereSugeevishere Member Posts: 11
Hi Guys,
Im extremely new to NAV. I need a help from You all.


I have used the Entry No as the Primary Key in my Temporary Table. I want to increment it by one when i post a record. I have set Auto increment Property. But its not properly working.
Can some one write a coding to increment the Entry no by 1 when i post record every Time.

Any Help will be appriciated.


Thank You.

Answers

  • kinekine Member Posts: 12,562
    Autoincrement is not working on temporary tables... could you be more specific on how you are using the table?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    This code works without setting the AutoIncrement-property:
    recYourTable.LOCKTABLE;
    IF recYourTable.FINDLAST THEN
      intNextEntryNo := intNextEntryNo + 1
    ELSE
      intNextEntryNo := 1;
    
    recYourTable.INIT;
    recYourTable."Entry No." := intNextEntryNo;
    ...
    
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • SugeevishereSugeevishere Member Posts: 11
    Hi Guys,

    Thanx for both's Reply.

    @ Kine I meant by Temporary table is I didn't change the Table's Property as Temporary. This is a Temporary table. It means I do not store in my DB. I delete this table when i finish the job.

    @ Luc van Dyck Its compiling perfectly. But The output is not corrrect. It Starts with Zero and It won't moves above that. Stays with Zero.
    Can You Provide me a Solution on this?
  • kinekine Member Posts: 12,562
    This is a Temporary table. It means I do not store in my DB. I delete this table when i finish the job.

    Thus you used Temporary on the record variable to set it as temporary... ;-) if it is not stored in DB, it is temporary... and the autoincrement is not working, and the Luc's code too because it is on real table and it is empty...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • SugeevishereSugeevishere Member Posts: 11
    YA. U R CORRECT.

    I JUST WANT TO IMPORT A TEXTFILE INTO A TABLE THROUGH DATAPORT. WHILE I IMPORT THIS ERROR OCCURS. THAT MEANS THE ENTRY DO NOT GOES ABOVE
    ZERO AND ONLY ONE RECORD IS GETTING PRINTED. WAT KIND OF SOLUTION FOR THIS?
  • kinekine Member Posts: 12,562
    1) Do not SHOUT...
    2) I hope that you are not importing ledger entries through dataport... rather fill the journal and post the journal to create the entries.
    3) You need to give us more details about how the dataport looks like, the data etc.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • SogSog Member Posts: 1,023
    If you start shouting, I'll just whisper your solution. Create a global variable of type intger, every time you initialise your new record for the new data add integer +=1 (is equal to integer := integer +1) set integer as the entry number, add your data and insert the record, you'll that it works.
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    @ Luc van Dyck Its compiling perfectly. But The output is not corrrect. It Starts with Zero and It won't moves above that. Stays with Zero.
    Can You Provide me a Solution on this?
    My code compiles and works perfectly... that is after changing it to this:
    recYourTable.LOCKTABLE;
    IF recYourTable.FINDLAST THEN
      intNextEntryNo := recYourTable."Entry No." + 1
    ELSE
      intNextEntryNo := 1;
    
    recYourTable.INIT;
    recYourTable."Entry No." := intNextEntryNo;
    ...
    
    If you don't show us your code, there is nothing we can do.

    I could come over and hold your hands while you are typing the code, but then you'll have to take care of my travel costs.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
Sign In or Register to comment.