item tracking. importing serial nos from external system

DmitriySozinov
Member Posts: 23
Hi,
Not an expert on item tracking here :-)
External system assigns serial numbers to Purchase Order Lines via BC extension method (see code below)
Sometimes, purchase order line already has the serial numbers assigned and they could be the same as those in external system.
External system does not know about it and still tries to assign serial numbers.
As a result, quantities in the tracking lines are wrong:

Instead it should be without undefined quantity:

How can you find if serial number already exists in the item tracking to skip it during the process of importing serial nos from external system?
Where is this information stored?

Not an expert on item tracking here :-)
External system assigns serial numbers to Purchase Order Lines via BC extension method (see code below)
Sometimes, purchase order line already has the serial numbers assigned and they could be the same as those in external system.
External system does not know about it and still tries to assign serial numbers.
As a result, quantities in the tracking lines are wrong:

Instead it should be without undefined quantity:

How can you find if serial number already exists in the item tracking to skip it during the process of importing serial nos from external system?
Where is this information stored?

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); end; // 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;
0
Best Answer
-
Solution that worked for me was just to check if incoming serial number is already assigned to a purchase line and skip the whole reservation line update process.
... For i := 1 to SerialNosList.Count do begin ExistingSerialFound := false; ItemTrackingEntries.reset; ItemTrackingEntries.SetRange("Source Type", DATABASE::"Purchase Line"); ItemTrackingEntries.SetRange("Source Subtype", PurchaseLine."Document Type"); ItemTrackingEntries.SetRange("Source ID", PurchaseLine."Document No."); ItemTrackingEntries.SetRange("Source Ref. No.", PurchaseLine."Line No."); ItemTrackingEntries.SetRange("Serial No.", SerialNosList.Get(i)); if ItemTrackingEntries.FindFirst() then ExistingSerialFound := true; if NOT ExistingSerialFound then begin ReservationEntry."Serial No." := SerialNosList.Get(i); ... CreateReservEntry.CreateReservEntryFor ... CreateReservEntry.CreateEntry ... end; ...
0
Answers
-
Hello,
Try instead ofIf NOT ReservationEntry.IsEmpty then begin ReservationEntry.DeleteAll(true); end;
use something like this:ReservationEntry.SetRange("Reservation Status", ReservationEntry."Reservation Status"::Reservation); If ReservationEntry.FindSet(true) then Repeat ReservationEntry2 := ReservationEntry; ReservEngineMgt.CancelReservation(ReservationEntry2); Until ReservationEntry.Next = 0; end; ReservationEntry.SetRange("Reservation Status"); If NOT ReservationEntry.IsEmpty then ReservationEntry.DeleteAll(true);
0 -
Solution that worked for me was just to check if incoming serial number is already assigned to a purchase line and skip the whole reservation line update process.
... For i := 1 to SerialNosList.Count do begin ExistingSerialFound := false; ItemTrackingEntries.reset; ItemTrackingEntries.SetRange("Source Type", DATABASE::"Purchase Line"); ItemTrackingEntries.SetRange("Source Subtype", PurchaseLine."Document Type"); ItemTrackingEntries.SetRange("Source ID", PurchaseLine."Document No."); ItemTrackingEntries.SetRange("Source Ref. No.", PurchaseLine."Line No."); ItemTrackingEntries.SetRange("Serial No.", SerialNosList.Get(i)); if ItemTrackingEntries.FindFirst() then ExistingSerialFound := true; if NOT ExistingSerialFound then begin ReservationEntry."Serial No." := SerialNosList.Get(i); ... CreateReservEntry.CreateReservEntryFor ... CreateReservEntry.CreateEntry ... end; ...
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