procedure AssignSerialNos(DocumentType: Integer; DocumentNumber: Code[20]; LineNo: Integer; SerialNosString: Text) Assigned: Boolean; var Item: Record Item; PurchaseHeader: Record "Purchase Header"; PurchaseLine: Record "Purchase Line"; ReservationEntry: Record "Reservation Entry"; TrackingSpecification: Record "Tracking Specification"; CreateReservEntry: Codeunit "Create Reserv. Entry"; ItemTrackingMgt: Codeunit "Item Tracking Management"; ItemTrackingPage: Page "Item Tracking Lines"; TrackingLinesInitialized: Boolean; i: Integer; SerialNosList: List of [Text]; RunMode: Enum "Item Tracking Run Mode"; begin SerialNosList := SerialNosString.Split(';'); if SerialNosList.Count = 0 then exit(false); PurchaseHeader.Get(DocumentType, DocumentNumber); //DocumentType:Order=1,Invoice=2,CreditNote=3 case PurchaseHeader."Document Type" of PurchaseHeader."Document Type"::Order: PurchaseLine.Get(PurchaseHeader."Document Type"::Order, PurchaseHeader."No.", LineNo); PurchaseHeader."Document Type"::Invoice: PurchaseLine.Get(PurchaseHeader."Document Type"::Invoice, PurchaseHeader."No.", LineNo); end; PurchaseLine.TestField(Type, 2); //2 = item PurchaseLine.TestField("No."); PurchaseLine.TestField("Quantity (Base)"); Item.Get(PurchaseLine."No."); Item.TestField("Item Tracking Code"); ReservationEntry.Reset(); ReservationEntry.SetRange("Source Type", DATABASE::"Purchase Line"); ReservationEntry.SetRange("Source Subtype", PurchaseLine."Document Type"); ReservationEntry.SetRange("Source ID", PurchaseLine."Document No."); ReservationEntry.SetRange("Source Ref. No.", PurchaseLine."Line No."); ReservationEntry.SetRange("Source Batch Name", ''); ReservationEntry.SetRange("Source Prod. Order Line", 0); If NOT ReservationEntry.IsEmpty then begin ReservationEntry.DeleteAll(true); end; For i := 1 to SerialNosList.Count do begin ReservationEntry."Serial No." := SerialNosList.Get(i); if PurchaseLine."Document Type" = PurchaseLine."Document Type"::Order then begin CreateReservEntry.CreateReservEntryFor( DATABASE::"Purchase Line", //ForType 1, //ForSubtype - Order PurchaseLine."Document No.", //ForID '', //ForBatchName 0, //ForProdOrderLine PurchaseLine."Line No.", //ForProdOrderLine 1, //ForQtyPerUOM 1, //Quantity 1, //QuantityBase ReservationEntry); //ForReservEntry end; if PurchaseLine."Document Type" = PurchaseLine."Document Type"::Invoice then begin CreateReservEntry.CreateReservEntryFor( DATABASE::"Purchase Line", //ForType 2, //ForSubtype - Invoice PurchaseLine."Document No.", //ForID '', //ForBatchName 0, //ForProdOrderLine PurchaseLine."Line No.", //ForProdOrderLine 1, //ForQtyPerUOM 1, //Quantity 1, //QuantityBase ReservationEntry); //ForReservEntry end; CreateReservEntry.CreateEntry( PurchaseLine."No.", PurchaseLine."Variant Code", PurchaseLine."Location Code", PurchaseLine.Description, PurchaseLine."Expected Receipt Date", 0D, 0, ReservationEntry."Reservation Status"::Surplus); // item tracking lines have to be synchronized between sales and purchase orders, when the purchase order is a drop shipment If PurchaseLine."Drop Shipment" then begin If not TrackingLinesInitialized then begin //PurchLineReserve.InitTrackingSpecification(PurchaseLineLoc,TrackingSpecification); TrackingSpecification.InitFromPurchLine(PurchaseLine); ItemTrackingPage.SetRunMode(Runmode::"Drop Shipment"); IF PurchaseLine."Sales Order No." <> '' THEN ItemTrackingPage.SetSecondSourceRowID(ItemTrackingMgt.ComposeRowID(DATABASE::"Sales Line", 1, PurchaseLine."Sales Order No.", '', 0, PurchaseLine."Sales Order Line No.")); ItemTrackingPage.SetSourceSpec(TrackingSpecification, PurchaseLine."Expected Receipt Date"); TrackingLinesInitialized := true; end; ItemTrackingPage.SynchronizeLinkedSources('') end; end; end;
Answers
So far the code that seems to work, but is still being tested looks like this: