Probably a stupid mistake, but can't FINDFIRST in dataset...

zacrzacr Member Posts: 19
This is probably a really stupid mistake, but I can't spot the problem so maybe a second set of eyes on it will help.

I'm trying to have some Whse. Item Journal batches require a Reason Code, so I added a Boolean field called 'Require Reason Code' on the batch record. If this is true, then the code should cycle through all the lines of the batch and return a FALSE value if any line is missing a Reason Code.

This function is on Page 7324 because I only want it called when a real user clicks on 'Register' or 'Register and Print'.

I've debugged it and it properly sets the filters for the Journal Template Name, Journal Batch Name, and Location Code. (Line No. is another primary key, but I don't filter on that because I want all lines.)

When it executes the FINDFIRST statement, it never finds the associated records (and there are five of them).

I'm drawing a blank why this isn't working. Any ideas?

Thanks in advance!

- Zac
WhseJournalBatch.GET("Journal Template Name","Journal Batch Name","Location Code");

// Reason Code not required, therefore post entries
IF NOT WhseJournalBatch."Require Reason Code"
  THEN EXIT(TRUE);

// Reason Code is required, so check each line ensure it is there.
lWhseJournalLine.SETRANGE("Journal Template Name",Rec."Journal Template Name");
lWhseJournalLine.SETRANGE(lWhseJournalLine."Journal Batch Name",Rec."Journal Batch Name");
lWhseJournalLine.SETRANGE(lWhseJournalLine."Location Code",Rec."Location Code");
IF lWhseJournalLine.FINDFIRST THEN BEGIN                // Problem is here - it never finds the set
  REPEAT
  IF lWhseJournalLine."Reason Code" = '' THEN EXIT(FALSE);   // Found a line without a Reason Code
  UNTIL lWhseJournalLine.NEXT = 0;
  EXIT(TRUE);                                                  // All lines have Reason Codes
  END;

Comments

  • txerifftxeriff Member Posts: 492
    have you tried findset?
  • zacrzacr Member Posts: 19
    txeriff wrote:
    have you tried findset?

    Yep, same result. I've tried FINDFIRST and FINDSET. I tried using different filter groups. I tried setting the filters differently. This should work, but doesn't.

    I'm wondering if filtering on records behaves differently from pages than tables. I put the code in the table and had the same results. This is so weird.

    - Zac
  • tinoruijstinoruijs Member Posts: 1,226
    In which trigger or function did you put the code?

    Tino Ruijs
    Microsoft Dynamics NAV specialist
  • vaprogvaprog Member Posts: 1,116
    Hi zacr
    • Please make sure lWhseJournalLine is RESET (i.e. does not have any unexpected filters set) before you start
    • Please make sure Rec is what you expect and contains the data you expect (i.e. is not a VAR you defined yourself, is not empty ...
    Apart from that, the code looks a little messy, but should work.

    I suggest you use
    lWhseJournalLine.COPY(Rec);
    WITH lWhseJournalLine DO BEGIN
      IF NOT FIND('=><') THEN
        EXIT(TRUE);
      SETRANGE("Journal Template Name","Journal Template Name");
      SETRANGE("Journal Batch Name","Journal Batch Name");
      SETRANGE("Location Code","Location Code");
      FILTERGROUP(2);
      SETRANGE("Reason Code",'');
      FILTERGROUP(0);
      IF FINDSET THEN
        REPEAT
          IF NOT EmptyLine THEN
            EXIT(FALSE);
        UNTIL NEXT = 0;
    END;
    EXIT(TRUE);
    
    This mimics the way later stages process the journal.
Sign In or Register to comment.