Print Only last record.

zulq
Member Posts: 204
Hi,
Having problems print the last record of a report. The last record is printed but it is repeated equal to the number of records found in the source table. For example if there are ten records in the source table the last record will be printed ten times.
Below is the code am using to fetch the last record:
Please help! ](*,)
Having problems print the last record of a report. The last record is printed but it is repeated equal to the number of records found in the source table. For example if there are ten records in the source table the last record will be printed ten times.
Below is the code am using to fetch the last record:
NRAPay.SETCURRENTKEY(RecordCount); NRAPay.SETRANGE(RecordCount); IF NRAPay.FIND('+') THEN BEGIN CurrReport.SHOWOUTPUT; END ELSE CurrReport.SKIP;
Please help! ](*,)
Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?
0
Answers
-
Hi...
Just try it by removing first 2 lines...
:!:0 -
Thanks suvidha but your suggestion will not work. That is the criteria for getting the last record using the recordcount.Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?0
-
You have a couple solutions to your problem.
One would be to maintain a variable called recIndex that increments everytime you go through the data item.OnAfterGetRecord: recIndex += 1; OnPreSection: IF recIndex = COUNT THEN CurrReport.SHOWOUTPUT := TRUE ELSE CurrReport.SHOWOUTPUT := FALSE;
This is not very elegant and requires much more processing than is necessary. I would use a slightly modified version of what you have.Create a data item of type integer. OnPreDataItem: SETRANGE(Number, 1); //So we only go through once myRec.SETRANGE(myCriteria); IF NOT myRec.FIND('+') THEN CurrReport.BREAK; Add text boxes to the body of the Integer data item referencing your myRec variable fields that you want to display.
Let me know if that doesn't make sense.0 -
You can find the last record value in OnPreDataItem. Then you can compare this value OnAfterGetRecord with the passing records like (In your method you find the last record but it doesn't mean that it is the current record. ):
OnPreDataItem
NRAPay.SETCURRENTKEY(RecordCount);
NRAPay.SETRANGE(RecordCount);
IF NRAPay.FIND('+') THEN
LastRecord:= NRAPay.RecordCount;
NRAPay.RESET;(if necessary)
OnAfterGetRecord
CurrReport.SHOWOUTPUT := NRAPay.RecordCount = LastRecord;
UfukUfuk Asci
Pargesoft0 -
Or change the Sort Order in the Properties of your Data Item and set CurrReport.Break after the first record has been printed.0
-
Thanks a lot all you guys...
I have solved it and below is how I did it:
OnPreDataItem:NRAPay.SETCURRENTKEY(RecordCount); NRAPay.SETRANGE(RecordCount); IF NRAPay.FIND('+') THEN LastRecord := NRAPay.RecordCount;
And OnAfterGetRecord:SETCURRENTKEY(RecordCount); SETRANGE(RecordCount,LastRecord); IF NOT FIND('+') THEN CurrReport.BREAK;
Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?0
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