Passing Filtered or Selected Records to a Codeunit

bmccarthy
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

Comments

  • bbrown
    bbrown Member Posts: 3,268
    Are you passing the record set "by reference"? Check the VAR box.
    There are no bugs - only undocumented features.
  • kriki
    kriki Member, Moderator Posts: 9,132
    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);
    END
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!