GET vs FIND

teeterteeter Member Posts: 46
Hello,
So after exhausting all other possibilities while debugging some code I ran into this situation and am hoping that somebody can explain it to me:

I'm running a report that will print all related posted sales invoices if a boolean is flagged TRUE. So I made the variable SalesInvoiceHeader to pass into
REPORT.RUN(50204,FALSE,FALSE,SalesInvoiceHeader);

Now, originally I was doing this ("Document No." is the PSI number):
IF SalesInvoiceHeader.GET("Document No.") THEN BEGIN
REPORT.RUN(50204,FALSE,FALSE,SalesInvoiceHeader);
The report would run, but the dataitem is empty and it would error out.

However, when I do this:
SalesInvoiceHeader.SETFILTER("No.","Document No.");
IF SalesInvoiceHeader.FIND('-') THEN BEGIN
REPORT.RUN(50204,FALSE,FALSE,SalesInvoiceHeader);
Everything worked fine.

So why does one work, but not the other??
They both will get me the one record I want to pass, I can't see the difference here...

Thanks in advance for some enlightenment ;)

Answers

  • jreynoldsjreynolds Member Posts: 175
    When you pass a record variable to a report like this you are not passing the current record, rather you are passing the view (i.e. key and filters) that is also part of a record variable. In the case of the FIND you have set filters on the record variable that limit the report to just those records. In the case of the GET you have not set any filters. Actually, I'm a little surprised by your example with the GET because in the absence of any filters on the record variable I would expect the report to run for all records. You can use SETRECFILTER to set filters on a record variable based on the vaues of the fields in the current record.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Try:
    SalesInvoiceHeader.SETFILTER("No.","Document No.");
    REPORT.RUN(50204,FALSE,FALSE,SalesInvoiceHeader);

    Find vs get is irrelevant
    David Singleton
  • DenSterDenSter Member Posts: 8,305
    If you go that way, you need to see if there is a record though, so you don't end up with an empty report:
    SalesInvoiceHeader.SETFILTER("No.","Document No."); 
    IF NOT SalesInvoiceHeader.ISEMPTY THEN 
      REPORT.RUN(50204,FALSE,FALSE,SalesInvoiceHeader);
    
  • David_SingletonDavid_Singleton Member Posts: 5,479
    DenSter wrote:
    If you go that way, you need to see if there is a record though, so you don't end up with an empty report:
    SalesInvoiceHeader.SETFILTER("No.","Document No."); 
    IF NOT SalesInvoiceHeader.ISEMPTY THEN 
      REPORT.RUN(50204,FALSE,FALSE,SalesInvoiceHeader);
    

    Why? The first command generated in the Report Execution is something like

    IF NOT rec.FINDSET then exit....

    So if there is no record in the filter, then the report wont run. :mrgreen:

    This is in that big flow chart in the user manual about how all objects execute.
    David Singleton
  • DenSterDenSter Member Posts: 8,305
    Sure it won't error out or anything, but don't you get the empty report window that says '0 pages generated' though?
  • teeterteeter Member Posts: 46
    OK, good to know the difference. Thanks for the wisdom guys! :D
  • David_SingletonDavid_Singleton Member Posts: 5,479
    DenSter wrote:
    Sure it won't error out or anything, but don't you get the empty report window that says '0 pages generated' though?

    Ah gotcha, some how I read "empty" as "error"
    David Singleton
Sign In or Register to comment.