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
0
Comments
2) What is the initial value of PeriodTransNo?
3) This part of code have no meaning for me because there is no context...
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
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.
}
}
right after the SETRANGE( "Posting Date", 010108D, 311208D ); ?
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?
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...
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
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...
I supposed that there must be a way other than changing the order of the keys.
Cheers,
Colin