How to split lines based on condition in Business Central Report

xhirvana
Member Posts: 5
We have this packing list report that we need to put pallet no. Column. Per sales line. Ex. Is that if we have an item no. With 1000 qty, if this item has 200cases per pallet,the item needs to split into 5 lines with qty 200 cases and with pallet no. 1 to 5. This will repeat for all the sales lines given the no. Of cases per pallet as maximum qty per line. Kindly help me with this one please...🙏. Thank you.
0
Comments
-
Hmm, this is only required in the report, not in BC itself?
In that case the simplest thing would be to create a global Temporary Table for your lines in the OnAfterGetRecord trigger of the header. And then use the Temporary Table as source for your Lines dataitem (and put it's property on temporary too).
You just loop through your record with the Lines (that is not Temporary).
For each line, get the Item and check that "No. Of Cases Max" has a value.
If its 0 then you don't need to split and you can just add the entire line to the Temporary Table.
If it is anything else (preferably a positive number ofcourse), then you need to continue in code to split it.
TotalQuantity := SalesLine.Quantity; MaxQtyPerLine := Item."No. Of Cases Max"; NoOfLines := Round(TotalQuantity / MaxQtyPerLine, 1, '>'); // Round it up to the nearest integer above the result, so 4.5 => 5
e.g.TotalQuantity := 900; MaxQtyPerLine := 200; NoOfLines := Round(900/ 200, 1, '>'); // Result is 5
And then just create the loop, so that would get you the code belowTotalQuantity := SalesLine.Quantity; MaxQtyPerLine := Item."No. Of Cases Max"; NoOfLines := Round(TotalQuantity / MaxQtyPerLine, 1, '>'); for Index = 1 to NoOfLines do begin NewQuantity := MaxQtyPerLine; if (Index = NoOfLines) then NewQuantity := TotalQuantity - ((NoOfLines - 1) * MaxQtyPerLine); TempSalesLine := SalesLine; TempSalesLine.Validate(Quantity, NewQuantity); TempSalesLine.Insert(false); end;
Hopefully this gives you an idea of how to do it.
I believe this is the cleanest way to get your report with more lines, while keeping it in Business Central on a single line.
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