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

zacr
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
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;
0
Comments
-
have you tried findset?0
-
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.
- Zac0 -
In which trigger or function did you put the code?
Tino Ruijs
Microsoft Dynamics NAV specialist0 -
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 ...
I suggest you uselWhseJournalLine.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.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K 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
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions