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
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
Tino Ruijs
Microsoft Dynamics NAV specialist
- 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 This mimics the way later stages process the journal.