How to modify the Sales Invoice Report to print Serial No./Lot No.

  2 minute read

[question-686336_1920](http://lh3.googleusercontent.com/-VKcsZ7PjwvI/VlvPHX0IcTI/AAAAAAAAJ1o/CIQPLc0Rrug/s1600-h/question-686336_1920%25255B2%25255D.jpg)
There are several requests on the Microsoft Dynamics Community forum to get an example or for the logic to print the serial no. or lot no. on the sales invoice report. In this post I will explain how to modify the standard sales invoice report (Report 10074: NAV 2015) to print the serial no. or lot no. on the report.For this purpose I have added a new function in the report 10074, called GetSerialLotNo ```python LOCAL PROCEDURE GetSerialLotNo@1240060002(); VAR ItemTrackingMgt@1240060000 : Codeunit 6500; TempItemLedgEntry@1240060001 : TEMPORARY Record 32; InvoiceRowID@1240060002 : Text[150]; LineNo@1240060003 : Integer; Inserted@1240060004 : Boolean; SerialLot@1240060005 : Code[60]; ValueEntryRelation@1240060006 : Record 6508; ValueEntry@1240060007 : Record 5802; ItemLedgEntry@1240060008 : Record 32; BEGIN IF TempSalesInvoiceLine.Type <> TempSalesInvoiceLine.Type::Item THEN EXIT; TempItemLedgEntry.RESET; TempItemLedgEntry.DELETEALL; InvoiceRowID := TempSalesInvoiceLine.RowID1; ValueEntryRelation.RESET; ValueEntryRelation.SETCURRENTKEY("Source RowId"); ValueEntryRelation.SETRANGE("Source RowId",InvoiceRowID); IF ValueEntryRelation.FIND('-') THEN BEGIN REPEAT ValueEntry.GET(ValueEntryRelation."Value Entry No."); ItemLedgEntry.GET(ValueEntry."Item Ledger Entry No."); TempItemLedgEntry := ItemLedgEntry; TempItemLedgEntry.Quantity := ValueEntry."Invoiced Quantity"; IF TempItemLedgEntry."Entry Type" IN [TempItemLedgEntry."Entry Type"::Purchase,TempItemLedgEntry."Entry Type"::Sale] THEN IF TempItemLedgEntry.Quantity <> 0 THEN TempItemLedgEntry.INSERT; UNTIL ValueEntryRelation.NEXT = 0; END; IF TempItemLedgEntry.FINDFIRST THEN REPEAT SerialLot := TempItemLedgEntry."Serial No." + ' ' + TempItemLedgEntry."Lot No."; WITH TempSalesInvoiceLine DO BEGIN INIT; "Document No." := "Sales Invoice Header"."No."; "Line No." := HighestLineNo + 10; HighestLineNo := "Line No."; END; IF STRLEN(SerialLot) + 1 <= MAXSTRLEN(TempSalesInvoiceLine.Description) THEN BEGIN TempSalesInvoiceLine.Description := SerialLot; TempSalesInvoiceLine."Description 2" := ''; END ELSE BEGIN SpacePointer := MAXSTRLEN(TempSalesInvoiceLine.Description) + 1; WHILE (SpacePointer > 1) AND (SerialLot[SpacePointer] <> ' ') DO SpacePointer := SpacePointer - 1; IF SpacePointer = 1 THEN SpacePointer := MAXSTRLEN(TempSalesInvoiceLine.Description) + 1; TempSalesInvoiceLine.Description := COPYSTR(SerialLot,1,SpacePointer - 1); TempSalesInvoiceLine."Description 2" := COPYSTR(COPYSTR(SerialLot,SpacePointer + 1),1,MAXSTRLEN(TempSalesInvoiceLine."Description 2")); END; TempSalesInvoiceLine.INSERT; UNTIL TempItemLedgEntry.NEXT = 0; END; ``` The Serial No. and Lot No. information is stored in the item ledger entry table, so the above function is used to retrieve all the item ledger entries associated to a sales invoice line, and then store those into a temporary ledger entry table, by using the temporary ledger entry table we populate TempSalesInvoiceline table, which will take care of displaying the values on the report without modifying/formatting RTC report. To print the serial no./ lot no. we just call the new function GetSerialLotNo on the OnAfterGetRecord of the Sales Invoice Line DataItem. Below is an example of the invoice report printing serial no. [image](http://lh3.googleusercontent.com/-t3Vr_aXlCy0/VlvPILkEQyI/AAAAAAAAJ1w/458geR0v20E/s1600-h/image%25255B2%25255D.png) Download the object from this link [Sales Invoice Report](http://1drv.ms/1OGITNh) Please leave your comments, feedback or any suggestions you have for me to improve my blog and also if you have any questions, feel free to post.

Leave a comment