This week a customer asked me to export tracking/reservation information (from table Reservation Entry) related to warehouse shipping order lines (custom table) to a file. Goal of the solution was to export shipping information to WinRoute, a third-party application for route calculation and distribution management.
Thinking about a solution reminded me of the fact that I have seen a lot of code, solving this, by simply getting the related records from the reservation entries. However, for a single orderline, multiple reservation entries (with the same lot no.) could exist. Solving this by just showing the records from the reservation entry table could show multiple records for the same lot/orderline. However, the customer needs these records per lot and order line accumulated.
In NAV you will find in codeunit 6500 a standard function called SumUpItemTracking wich will ‘sumup’ all the reservation entries from the recordset you have passed, and return accumulated data in record variable TmpHandlingSpecification.
This record variable must be declared as a global; make sure you set this record variable (table Tracking Specification) to temporary or you will end up breaking live data if put into production. Below you find a code snippet, I reduced the code to make it more readable. The call to the function is on line 23.
// Get order lines for selected/filtered shipping orders WhseShippingOrderLine.SETRANGE("Whse. Shipping Order No.","No."); IF WhseShippingOrderLine.FINDFIRST THEN REPEAT // find related reservation entries per orderline ReservationEntry.RESET; ReservationEntry.SETRANGE("Whse. Shipping Order No.",WhseShippingOrderLine."Whse. Shipping Order No."); ReservationEntry.SETRANGE("Whse. Ship. Order Line No.",WhseShippingOrderLine."Line No."); ReservationEntry.SETFILTER("Qty. to Handle (Base)",'<>0'); IF ReservationEntry.FINDFIRST THEN // Send the reservation entries to our function and get the TempHandlingSpecification in return: ItemTrckMgt.SumUpItemTracking(ReservationEntry,TempHandlingSpecification,TRUE,TRUE) // Process the records in TempHandlingSpecification: IF TempHandlingSpecification.FINDFIRST THEN REPEAT LineNo := LineNo + 10000; // Put lines and orderinformation in WinRoute table WinRouteExport.INIT; WinRouteExport.fIntLineNo := LineNo; WinRouteExport.fCodUserID := USERID; WinRouteExport.fCodExternalID := STRSUBSTNO('%1%2',"No.",TempHandlingSpecification."Lot No."); WinRouteExport.fIntMass1 := TempHandlingSpecification."Qty. of Packagings" * -1; WinRouteExport.INSERT; UNTIL TempHandlingSpecification.NEXT = 0; UNTIL WhseShippingOrderLine.NEXT = 0;
This is only one example of the many standard functions that exist in NAV. So, my tip for today: before re-inventing the wheel, first explore in standard code how things are solved in standard NAV:-)