web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Business Central forum

Item Journal Line Table Records are getting deleted.

(0) ShareShare
ReportReport
Posted on by 95

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
  • Suggested answer
    I Gusti Made Ari Profile Picture
    3,608 on at

    Please check  "schemaUpdateMode" in your launch.json file.

    Make sure it is not "Recreate"

  • Mesam Profile Picture
    95 on at

    It is not on Recreate. It is on Synchronize.

  • Peter Zentner Profile Picture
    390 on at

    If the lines get cleared out when you republish the extension, it could also be something in your upgrade code that clears them out. However, this does not take care of the "restart the tenant" issue. Overall, there could be a few different issues and they should all somehow be around some event that possibly deletes the item journal template or the batch.

    You could setup the change log to for item journal lines to determine, if those records get deleted. If you set tracking for deletion only, you could see this probably. Based on that, you would have to determine what your next step is.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans