How do I add sequential numbers to G/L register table

colingbradleycolingbradley Member Posts: 162
edited 2009-04-17 in Navision Attain
Ver 3.1

I have created a new field in the G/L Register table, "Period Trans. No." and need to populate it with a sequential number based on the posting date range (another new field)..

However, the code below is not doing it for me, I get one number for each date:

01/01/08 = 1

01/01/08 (next record) = 0 (not assigned a number).
(original post had the wrong date, sorry)
Here is my code. "Period Trans. No." is assigned a value of 1 before processing;

//SORTING(Posting Date) ORDER(Ascending)

SETRANGE("Posting Date", PeriodStart,PeriodEnd);
"Period Trans. No." := PeriodTransNo;
MODIFY;
PeriodTransNo := PeriodTransNo +1;

THE ANSWER
Changed the order of the keys:
Key
No.
Creation Date
Source Code,Journal Batch Name,Creation Date
Posting Date
Posting Date,Period Trans. No.

Putting the Posting Date,Period Trans. No. key last did the trick.
\:D/

Thanks for all the help guys.
Experience is what you get when you hoped to get money

Comments

  • kinekine Member Posts: 12,562
    1) Over which record variable is the code executed?
    2) What is the initial value of PeriodTransNo?
    3) This part of code have no meaning for me because there is no context...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • colingbradleycolingbradley Member Posts: 162
    Here is the report:
    Table 45 with additional fields "Posting Date" and "Period Trans. No.".
    All Posting Date fields have a date value <> 0D.
    The date range for this excercise has been hard coded.
    The global variable PeriodTransNo has a value of 1 OnInitReport.
    The problem is I get only some records, see picture.
    //
    OBJECT Report 80226 Update registers with PerTrNo
    {
    OBJECT-PROPERTIES
    {
    Date=17/04/09;
    Time=16:33:01;
    Modified=Yes;
    Version List=;
    }
    PROPERTIES
    {
    ProcessingOnly=Yes;
    OnInitReport=BEGIN
    PeriodTransNo := 1;
    END;

    }
    DATAITEMS
    {
    { PROPERTIES
    {
    DataItemTable=Table45;
    DataItemTableView=SORTING(Posting Date)
    ORDER(Ascending);
    OnPreDataItem=BEGIN
    SETRANGE( "Posting Date", 010108D, 311208D );
    END;

    OnAfterGetRecord=BEGIN
    "Period Trans. No." := PeriodTransNo;
    PeriodTransNo := PeriodTransNo + 1;
    MODIFY;
    END;

    ReqFilterFields=Posting Date;
    }
    SECTIONS
    {
    { PROPERTIES
    {
    SectionType=Body;
    SectionWidth=12000;
    SectionHeight=846;
    }
    CONTROLS
    {
    }
    }
    }
    }
    }
    REQUESTFORM
    {
    PROPERTIES
    {
    Width=9020;
    Height=3410;
    }
    CONTROLS
    {
    }
    }
    CODE
    {
    VAR
    PeriodTransNo@1000000000 : Integer;

    BEGIN
    END.
    }
    }
    Experience is what you get when you hoped to get money
  • kapamaroukapamarou Member Posts: 1,152
    Tried a IF NOT FIND(-) THEN CurrReport.BREAK;

    right after the SETRANGE( "Posting Date", 010108D, 311208D ); ?
  • colingbradleycolingbradley Member Posts: 162
    Can't see how that would help..I need it to keep going to the next record in sequence, it will run out of records in the selection.

    I have just tried using a record variable, code:

    CLEAR(glregister);
    glregister.SETCURRENTKEY("Posting Date");
    glregister.SETRANGE( "Posting Date", 010108D, 311208D );
    IF glregister.FIND('-') THEN BEGIN //WITH glregister DO
    REPEAT
    glregister."Period Trans. No." := PeriodTransNo;
    glregister.MODIFY;
    PeriodTransNo := PeriodTransNo + 1;
    UNTIL glregister.NEXT = 0;
    END;

    Same result...may be it is not possible?
    Experience is what you get when you hoped to get money
  • kapamaroukapamarou Member Posts: 1,152
    The code I suggested won't harm since it is on the On Predata item...

    Any way.
    You say
    glregister.SETCURRENTKEY("Posting Date");

    Could your first key that starts with posting date consist of
    "posting date" and "Period Trans. No."? If that is the case then modifying the Period Trans. No. filed will move your "record pointer" after the unmodified records when the NEXT command is issued...
  • colingbradleycolingbradley Member Posts: 162
    Hi,

    Thanks. I have posted the answer in my original post.
    It was the order of the keys.
    So you were on the right track but it was just as easy to change the order of the keys then the report works fine.

    Cheers,
    Colin
    Experience is what you get when you hoped to get money
  • kapamaroukapamarou Member Posts: 1,152
    Great!

    This is a problem when defining keys.

    But you can override this problem in a couple of ways...

    You can use the FINDSET with the appropriate parameters or modify the record through another variable and not the one the loop is based on...

    Just some information... :D
  • colingbradleycolingbradley Member Posts: 162
    That is very useful, thank you.
    I supposed that there must be a way other than changing the order of the keys.
    Cheers,
    Colin
    Experience is what you get when you hoped to get money
Sign In or Register to comment.