Friday, July 6, 2018

Dynamics NAV - Adjust Costs job takes very long.

Create a routine that runs the adjust cost job for one item at a time. in small groups.
Eventually, once all of the items have had the adjust cost complete relatively recently, the entire job will run faster.

Get all items where "Cost is Adjusted" = False

Write a routine to get the next X items ahead in the list.
------------------------------------
GetEndItemRange(ItmRange : Integer) : Text[50]
Itm3.SETCURRENTKEY("No.");
Itm3.SETRANGE("Cost is Adjusted",FALSE);
Itm3.SETFILTER("No.",'>='+FirstItem);
Ct:= 0;
IF Itm3.FINDFIRST THEN BEGIN
  REPEAT
    Ct:= Ct + 1;
    Itm3.NEXT;
    TheNo := Itm3."No.";
  UNTIL Ct = ItmRange;
  EXIT(TheNo);
END;

Call the Adjust Cost Item Entries with the item number filter begin and end to run it only for that small range
-------------------------------------
 Itm2.SETRANGE("No.",CurrItemNo, EndCurrItemNo);
    InvtAdjmt.SetFilterItem(Itm2);
    InvtAdjmt.MakeMultiLevelAdjmt;

Include a COMMIT at the end of the REPEAT to ensure that batch is written so the whole list doesn't get undone if it runs into an error.

No comments:

Post a Comment