Options

How to create a Reservation Entry?

Hi experts,

I'm using NAV 2015 and have created a purchase table with some purchase lines.

Now I need to register one or more Serial numbers and/or Lot numbers regarding one of the lines. How do I do that using C/SIDE code?

I have tried this, but it doesn't create anything:

// I have found the purchLine
doFullReserve := TRUE;
reservationManagement.SetPurchLine(purchLine);
reservationManagement.AutoReserve(doFullReserve, purchLine.Description, WORKDATE, purchLine."Outstanding Quantity", purchLine."Outstanding Qty. (Base)");

I think AutoReserve() cannot find my purchHeader.

It would be really great if someone can give an example where more Serial numbers or Lot numbers can be saved to the same purchase line.

Best Answer

Answers

  • Options
    AlexeyShaminAlexeyShamin Member Posts: 80
    Hello!
    try create item tracking:
    PurchReservEntry.InitTrackingSpecification(PurchLIne, NewTrackingSpecification);
    NewTrackingSpecification."Serial No." := SerialNo;
    NewTrackingSpecification."Lot No." := LotNo;
    NewTrackingSpecification."CD No." := CDNo;
    NewTrackingSpecification.VALIDATE("Quantity (Base)", QuantityBase);
    CreateReservEntry.SetDates(0D,0D);
    CreateReservEntry.SetApplyFromEntryNo(0);
    CreateReservEntry.SetApplyToEntryNo(0);
    CreateReservEntry.CreateReservEntryFor(
    NewTrackingSpecification."Source Type",
    NewTrackingSpecification."Source Subtype",
    NewTrackingSpecification."Source ID",
    NewTrackingSpecification."Source Batch Name",
    NewTrackingSpecification."Source Prod. Order Line",
    NewTrackingSpecification."Source Ref. No.",
    NewTrackingSpecification."Qty. per Unit of Measure",
    0,
    NewTrackingSpecification."Quantity (Base)",
    NewTrackingSpecification."Serial No.",
    NewTrackingSpecification."Lot No.",
    NewTrackingSpecification."CD No.");

    CreateReservEntry.CreateEntry(NewTrackingSpecification."Item No.",
    NewTrackingSpecification."Variant Code",
    NewTrackingSpecification."Location Code",
    NewTrackingSpecification.Description,
    PurchLIne."Expected Receipt Date",
    PurchLIne."Expected Receipt Date" ,0,2);

    CurrentSourceRowID := ItemTrackingMgt.ComposeRowID(NewTrackingSpecification."Source Type",
    NewTrackingSpecification."Source Subtype",NewTrackingSpecification."Source ID",
    NewTrackingSpecification."Source Batch Name",NewTrackingSpecification."Source Prod. Order Line",
    NewTrackingSpecification."Source Ref. No.");
    SalesLine.RESET;
    SalesLine.GET(SalesLine."Document Type"::Order, PurchLIne."Sales Order No.", PurchLIne."Sales Order Line No.");
    SaleReservEntry.InitTrackingSpecification(SalesLine, NewTrackingSpecification);
    SecondSourceRowID := ItemTrackingMgt.ComposeRowID(NewTrackingSpecification."Source Type",
    NewTrackingSpecification."Source Subtype",NewTrackingSpecification."Source ID",
    NewTrackingSpecification."Source Batch Name",NewTrackingSpecification."Source Prod. Order Line",
    NewTrackingSpecification."Source Ref. No.");
    ItemTrackingMgt.SynchronizeItemTracking(CurrentSourceRowID, SecondSourceRowID, '');


    NewTrackingSpecification - Table 336
    PurchReservEntry - Codeunit Purch/ Line-Reserve
    CreateReservEntry - Codeunit Create REserv. Entry
    CurrentSourceRowID and SecondSourceRowID - Text 100

    And After create Reservation
  • Options
    MortenSteengaardMortenSteengaard Member Posts: 131
    Hi Alexey,

    Thank you very much for your reply.

    I am not sure if I wrote my question clear enough.

    I need to make some code that do the same as what is done, when a user on a purchLine enters a number of SerialNo's and/or LotNo's in the menu "Item Tracking Lines". There is no records in "Reservation Entries" and I shouldn't use that. (I think that the code, I have found somewhere on the net and that I put in my question, was ment to create a reservation, but I shouldn't do that.)

    I also don't have a salesLine. The purchLine is not created because of a salesLine. It is just created manually.

    So, should I delete the last lines from "SalesLine.RESET" and to the bottom?

    (I also don't have the field NewTrackingSpecification."CD No.". I guess it comes in newer versions of NAV.)

    Best regards,

    Morten
  • Options
    MortenSteengaardMortenSteengaard Member Posts: 131
    Hi Alexey,

    Thank you very much! It works fine.

    If I buy 3 items (on one purchase line) and receive and post 2 and then later try to use this code, I get an error. I solved it by setting NewTrackingSpecification."Quantity Handled (Base)" and NewTrackingSpecification."Quantity (Base)" to 1.

    So now the code looks like this:

    NewTrackingSpecification.RESET;
    PurchReservEntry.InitTrackingSpecification(purchLine, NewTrackingSpecification);
    NewTrackingSpecification."Serial No." := serialNo;
    NewTrackingSpecification."Lot No." := lotNo;

    NewTrackingSpecification.VALIDATE("Quantity Handled (Base)", 1);
    NewTrackingSpecification.VALIDATE("Quantity (Base)", 1);

    CreateReservEntry.SetDates(0D,0D);
    CreateReservEntry.SetApplyFromEntryNo(0);
    CreateReservEntry.SetApplyToEntryNo(0);
    CreateReservEntry.CreateReservEntryFor(NewTrackingSpecification."Source Type",
    NewTrackingSpecification."Source Subtype",
    NewTrackingSpecification."Source ID",
    NewTrackingSpecification."Source Batch Name",
    NewTrackingSpecification."Source Prod. Order Line",
    NewTrackingSpecification."Source Ref. No.",
    NewTrackingSpecification."Qty. per Unit of Measure",
    0,
    NewTrackingSpecification."Quantity (Base)",
    NewTrackingSpecification."Serial No.",
    NewTrackingSpecification."Lot No.");

    CreateReservEntry.CreateEntry(NewTrackingSpecification."Item No.",
    NewTrackingSpecification."Variant Code",
    NewTrackingSpecification."Location Code",
    NewTrackingSpecification.Description,
    purchLine."Expected Receipt Date",
    purchLine."Expected Receipt Date", 0, 3);

    Once again, thank you very much, Alexey!

    Best regards,

    Morten
Sign In or Register to comment.