Insert record in loop not find in the next iteration (Dynamics BC170)

navid
Member Posts: 5
I am trying to write this code
basically if one header is inserted for a vendor for that day I want to use that header to insert more line. and so on ... But after inserting one header when the record repeats it does not find the inserted record for same vendor. What did I wrong here can any one suggest me? Thanks in advance.
ItemDistributions.SetRange("DSM Code", ordPlnHeader_rec.DMS); ItemDistributions.SetRange("Item No", itemNo); ItemDistributions.SetRange("Supplier Type", ItemDistributions."Supplier Type"::"Sole Supplier"); if ItemDistributions.FindFirst() then begin repeat PurchaseHeader.Reset(); PurchaseHeader.SetRange("Buy-from Vendor No.", ItemDistributions."Vendor No"); PurchaseHeader.SetRange("Document Date", Today); if not PurchaseHeader.FindFirst() then begin PurchSetup.Get(); PurchaseHeader.Init(); PurchaseHeader.validate("Document Type", PurchaseHeader."Document Type"::Order); PurchaseHeader.validate("No.", ''); PurchaseHeader.validate("Buy-from Vendor No.", ItemDistributions."Vendor No"); PurchaseHeader.Validate("Document Date", Today); PurchaseHeader.Insert(true); end; //Insert the lines... Until ItemDistributions.next = 0;
basically if one header is inserted for a vendor for that day I want to use that header to insert more line. and so on ... But after inserting one header when the record repeats it does not find the inserted record for same vendor. What did I wrong here can any one suggest me? Thanks in advance.
0
Answers
-
You have ThisWeek variable for document date and filter is Today.0
-
Thanks for your answer. but this thisweek is same as today (I have corrected in the question). Even if I use today in both place same thing is happening.0
-
The Document Date is set to WorkDate during OnInsert. Follow the code and see if you can find it.
Also, FindFirst only gets one record. It works because it's a common mistake, but when the code gets to the 'Next' it has to go back to the database for the next record. When you need to loop through records, you should use FindSet, that gets the whole set of records in one database trip1 -
Thanks a lot for the answer and nice tips. I did not know about this.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