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

colingbradley
Member Posts: 162
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.
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
-
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...0 -
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 money0 -
Tried a IF NOT FIND(-) THEN CurrReport.BREAK;
right after the SETRANGE( "Posting Date", 010108D, 311208D ); ?0 -
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 money0 -
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...0 -
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,
ColinExperience is what you get when you hoped to get money0 -
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...0 -
That is very useful, thank you.
I supposed that there must be a way other than changing the order of the keys.
Cheers,
ColinExperience is what you get when you hoped to get money0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions