RE: Creating Item Tracking Lines for Sales Order with C/AL + How to get Item Available Quantity with C/AL
Hi,
I remember this post and the solution from Robert Stefanetti:
community.dynamics.com/.../how-to-create-item-tracking-line-from-c-al
I tried this code as different from the link inside this post. I did this for Purchase Line and Sales Line to handle thes in a warehouse document.
It seems the rec337 table (here known as Reservation) is as here below:
For Purchase Line:
Reservation."Reservation Status" := Reservation."Reservation Status"::Prospect;
Reservation."Creation Date" := WORKDATE();
Reservation."Source Type" := PurchLine.RecordId().TableNo();
Reservation."Source Subtype" := PurchLine."Document Type";
Reservation."Source ID" := PurchLine."Document No.";
Reservation."Source Batch Name" := '';
Reservation."Source Ref. No." := PurchLine."Line No.";
Reservation.Positive := TRUE;
Reservation.VALIDATE("Location Code", PurchLine."Location Code");
// Reservation.VALIDATE("Bin Code", ItemJnlLine."Bin Code");
Reservation.VALIDATE("Item No.", PurchLine."No.");
Reservation.VALIDATE("Quantity (Base)", PurchLine."Quantity (Base)");
Reservation.VALIDATE(Quantity, PurchLine.Quantity);
Reservation."Item Tracking" := Reservation."Item Tracking"::"Lot No."; // IF LOT OR TRACKING in this sample LOT
Reservation."Lot No." := LotNoToInsert;
Reservation."Expiration Date" := Expires;
IF Reservation.INSERT(TRUE) THEN BEGIN
//Lot Info creation
LotNoInformation.INIT();
LotNoInformation.VALIDATE("Item No.", Reservation."Item No.");
LotNoInformation.VALIDATE("Lot No.", Reservation."Lot No.");
if not LotNoInformation.INSERT(TRUE) then LotNoInformation.Modify(TRUE);
END
For Sales Line:
Reservation."Reservation Status" := Reservation."Reservation Status"::Prospect;
Reservation."Creation Date" := WORKDATE();
Reservation."Source Type" := SaleLine.RecordId().TableNo();
Reservation."Source Subtype" := SaleLine."Document Type";
Reservation."Source ID" := SaleLine."Document No.";
Reservation."Source Batch Name" := '';
Reservation."Source Ref. No." := SaleLine."Line No.";
Reservation.Positive := TRUE;
Reservation.VALIDATE("Location Code", SaleLine."Location Code");
// Reservation.VALIDATE("Bin Code", ItemJnlLine."Bin Code");
Reservation.VALIDATE("Item No.", SaleLine."No.");
Reservation.VALIDATE("Quantity (Base)", SaleLine."Quantity (Base)");
Reservation.VALIDATE(Quantity, SaleLine.Quantity);
Reservation."Item Tracking" := Reservation."Item Tracking"::"Lot No."; // IF LOT OR TRACKING in this sample LOT
Reservation."Lot No." := LotNoToInsert;
Reservation."Expiration Date" := Expires;
IF Reservation.INSERT(TRUE) THEN BEGIN
//Lot Info creation
LotNoInformation.INIT();
LotNoInformation.VALIDATE("Item No.", Reservation."Item No.");
LotNoInformation.VALIDATE("Lot No.", Reservation."Lot No.");
if not LotNoInformation.INSERT(TRUE) then LotNoInformation.Modify(TRUE);
END
I also remarked that the Quantity (base)/ Quantity field must be different from 0 to show up the tracking line, but there must be something more and I think about the above fields because they are different from the Item Journal.
I edited this post because after modify the Source batch Name to empty it works.
Best regards