Passing Filtered or Selected Records to a Codeunit
bmccarthy
Member Posts: 48
Hey,
Can anyone explain to me what I'm doing wrong.
I want to pass a filtered set of records to a codeunit and then within the codeunit loop through the filtered list. To test this I have done the following
In the list form, on a button trigger after filtering to 3 records from 25.
IF Rec.FIND('-') THEN
REPEAT
theCount := theCount +1;
UNTIL Rec.NEXT = 0;
MESSAGE('COUNT = ' + FORMAT(theCount));
MyCodeUnit.SendReports(Rec);
Then in my codeunit I rerun the count:
SendReports(Recs : Record "Sales Invoice Header")
IF Recs.FINDSET THEN BEGIN
REPEAT
theCount := theCount +1;
UNTIL Recs.NEXT = 0;
MESSAGE('COUNT = ' + FORMAT(theCount));
END
When I press my button, first message box says '3' second one from the codeunit says '25'?
Why does it drop the filter? How do I get it back? Why in other situations like this can I not isolate one or a couple of records (thruough selection or filtering)) and then just pass those around?
Any help here would be really appreciated as I'm ](*,)
Cheers
Bryan
Can anyone explain to me what I'm doing wrong.
I want to pass a filtered set of records to a codeunit and then within the codeunit loop through the filtered list. To test this I have done the following
In the list form, on a button trigger after filtering to 3 records from 25.
IF Rec.FIND('-') THEN
REPEAT
theCount := theCount +1;
UNTIL Rec.NEXT = 0;
MESSAGE('COUNT = ' + FORMAT(theCount));
MyCodeUnit.SendReports(Rec);
Then in my codeunit I rerun the count:
SendReports(Recs : Record "Sales Invoice Header")
IF Recs.FINDSET THEN BEGIN
REPEAT
theCount := theCount +1;
UNTIL Recs.NEXT = 0;
MESSAGE('COUNT = ' + FORMAT(theCount));
END
When I press my button, first message box says '3' second one from the codeunit says '25'?
Why does it drop the filter? How do I get it back? Why in other situations like this can I not isolate one or a couple of records (thruough selection or filtering)) and then just pass those around?
Any help here would be really appreciated as I'm ](*,)
Cheers
Bryan
0
Comments
-
Are you passing the record set "by reference"? Check the VAR box.There are no bugs - only undocumented features.0
-
Like bbrown wrote, you need to click the VAR box in the parameter.
And you can also speed up and simplify the process.
-Use COUNT, instead of looping. The COUNT happens on the server and sends only the result, but NOT all the records
-the first parameter of MESSAGE in reality is a format-string and the next parameters are parameters for the format-string.
So in short this will be your function:SendReports(VAR Recs : Record "Sales Invoice Header") MESSAGE('COUNT = %1',Recs.COUNT); ENDRegards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions