Skip to main content
Business Central forum
Suggested answer

Why is my Codeunit to update PlanningLine dates failing?

editSubscribe (0) ShareShare
ReportReport
Posted on by UG Leader

I've written the below codeunit with the goal of updating all Planning Line's "Planning Date" values whenever the related Jobs "Starting Date" value changes. Why is the Planning Date field not updating?

// Codeunit Source
codeunit 50102 UpdatePlanningLines
{
    procedure ByJobStartDate(Job: Record Job)

    begin
        PlanningLines.SetRange("Job No.", Job."No.");
        if PlanningLines.FindSet() then
            repeat
                Message('Looping task '   PlanningLines."Job Task No."   ' and setting Planning Date to '   Format(Job."Starting Date"));
                PlanningLines."Planning Date" := Job."Starting Date";
            until PlanningLines.next = 0;
    end;

    var
        PlanningLines: Record "Job Planning Line";
}

//On Job Card
modify("Starting Date")
{
    trigger OnAfterValidate()
    begin
        if Rec."Starting Date" <> 0D then begin
            UpdatePlanningLines.ByJobStartDate(Rec);
        end;
    end;
}

Categories:
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 59,926 Super User on at
    RE: Why is my Codeunit to update PlanningLine dates failing?

    Hi, as Wolfind mentioned, you need to use Record.Modify([Boolean]) Method here.

    pastedimage1647389931842v1.png

    In addition, if you are all modified to be the same date, please consider using the ModifyAll method, this will not require a loop

    pastedimage1647390006175v2.png

    More details:

    https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-insert-modify-modifyall-delete-and-deleteall-methods

    Hope this will help.

    Thanks.

    ZHU

  • Suggested answer
    Community Member Profile Picture
    Community Member UG Leader on at
    RE: Why is my Codeunit to update PlanningLine dates failing?

    Solved it - Needed to finish off REPEAT iteration with:

    PlanningLines.Modify();

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,045 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,570 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans