Item Journal Line Table's Records are getting deleted by themselves.

mysamzamysamza Member Posts: 66
I wrote this procedure what will take lines and add them to the Item Journal Line table at the click of a button called "Issue Material"
Here is the procedure;
procedure IssueMaterial(IncomingLine: Record "Purchase Requisition Line")
var
ItemCont: Record "Item Journal Line";
begin
IF ItemCont.FindLast then begin
ItemCont."Line No." := ItemCont."Line No." + 10000;
end;
with ItemCont do begin
ItemCont.Init();
ItemCont."Journal Template Name" := 'Item';
Validate("Item No.", IncomingLine."No.");
ItemCont."Posting Date" := WorkDate();
Validate("Location Code", IncomingLine.Location);
ItemCont."Entry Type" := ItemCont."Entry Type"::"Negative Adjmt.";
ItemCont."Journal Batch Name" := 'Default';
ItemCont."Line No." := IncomingLine."Line No.";
Validate(Quantity, IncomingLine.Quantity);
Validate(Amount, IncomingLine.Amount);
Validate("Unit Cost", IncomingLine."Unit Cost");
ItemCont.Insert();
end;
Message('%1 has been successfully created', IncomingLine."No.");
end;

Here is the code at the Action (Button) I wrote;

trigger OnAction()
var
codeunitcont: Codeunit "Purchase Req. Mgmt.";
PurchReqLine: Record "Purchase Requisition Line";
begin
CurrPage.SetSelectionFilter(PurchReqLine);
IF PurchReqLine.FindSet then
repeat
PurchReqLine.TestField(PurchReqLine.Location);
codeunitcont.IssueMaterial(PurchReqLine);
until PurchReqLine.Next = 0;
end;

It works fine. I get my lines moved to the Item Journal Table, however, once I restart the Tenant or Rebuild and Republish an extension my Item Journal Table loses its records!
Thank you for your advice on what could be the issue

Answers

  • lubostlubost Member Posts: 623
    ItemCont.Init(); in your code may empty "Line No." field. Use SetUpNewLine function in table 83.
Sign In or Register to comment.