Calculate Date After compare and check Leadtime

Hi Everybody,

When I calculation Date form Order Date with Expected Receipt as a result type Integer.

CountDate:=“Expected Receipt Date”-PurchHeader.“Order Date”;

I want check CountDate > ItemVendor.“Lead Time Calculation”

But I can not convert Integer data type to DateFormula for comparison.

Please help me, give me a solution.

Thanks so much

Best Regards,

dinhson

Hi,

What about doing a CalcDate(ItemVendor.“Lead Time Calculation”,PurchHeader.“Order Date”) and comparing it with Expected Receipt Date?.

Thanks for reply. But when add (DateOrder : Type : Date)

DateOrder:=CALCDATE(ItemVendor.“Lead Time Calculation”, PurchHeader.“Order Date”);
then error :
"Microsoft Dynamics NAV

Break On Error Message:

You cannot base a date calculation on an undefined date. Date: 0D Formula: 10

OK
---------------------------"

Please help me. Thanks so much.

Hope your order date is not blank and date formula in correct format

Thanks you manjusree.

I’m sure PurchaseHeader."Order date,“Lead Time Calculation” is not blank. And code i write here. You check what the problem is here. Thanks

IF ("Document Type"="Document Type"::Order) THEN
BEGIN
  Rec.RESET;
  PurchHeader.SETRANGE(PurchHeader."No.","Document No.");
  ItemVendor.SETRANGE(ItemVendor."Vendor No.","Buy-from Vendor No.");
  ItemVendor.SETRANGE(ItemVendor."Vendor Item No.","No.");
  SETFILTER(Type,'%1',Type::Item);
  SETFILTER(Type, '>1');
  IF Rec.FINDSET THEN BEGIN
      ItemVendor.GET("Buy-from Vendor No.","No.") ;
      Leadtime :=ItemVendor."Lead Time Calculation";   
      END;
     ExpOrder:=CALCDATE(Leadtime, PurchHeader."Order Date");
     MESSAGE(Txt001,'%1',ExpOrder);    //Show check "Lead Time Calculation"
 END;

Hi,

I think your code is in purchase line table. Please try something like this:-

IF (“Document Type”=“Document Type”::Order) THEN
BEGIN
IF Type=Type::Item THEN BEGIN
PurchHeader.RESET;
IF PurchHeader.GET(PurchHeader.“No.”,“Document No.”) THEN BEGIN
ItemVendor.RESET;
IF ItemVendor.GET(“Buy-from Vendor No.”,“No.”,“Variant Code”) THEN
Leadtime :=ItemVendor.“Lead Time Calculation”;
ExpOrder:=CALCDATE(Leadtime, PurchHeader.“Order Date”);
MESSAGE(Txt001,’%1’,ExpOrder); //Show check “Lead Time Calculation”
END;
END;
END;

Thanks you manjusree.

I write code in page (ID 54- Purchase Order Subform).

When change code then Error “The type NavOption is unknown.”

And i debug then Document Type for Purchase Header is : “Quote”

pastedimage1512918648460v1.png

Please help me. Thanks so much.

Hi,

Sorry, did not notice, there was an issue with the GET statement in my code. Please change it to
IF PurchHeader.GET(“Document Type”,“Document No.”) THEN BEGIN

Thanks you mạnusree

After change “IF PurchHeader.GET(“Document Type”,“Document No.”) THEN BEGIN” then Ok.

But variable ExpOrder:=’’ . I tried as failed.

pastedimage1512959004576v1.png

Leadtime =10D

pastedimage1512959020132v2.png

PurchHeader.“Order Date”=‘12/08/2017’

But ExpOrder:=’’ It does not calculate the ExpOrder value.

Hi,

Not sure why are you adding XRec.“Expected Receipt Date”. Just add

ExpOrder:=CALCDATE(Leadtime, PurchHeader.“Order Date”);
ERROR(FORMAT(ExpOrder));

This will work.

Thanks you manjusree.
I’m work.

Hi Dinhson,

Not saying that it would not work in all situations, but you do have a few more errors/problems in that code! Plus you could do it much simpler.

IF ("Document Type" <> "Document Type"::Order) OR (Type <> Type::Item) THEN EXIT;
IF NOT PurchHeader.GET("Document Type","Document No.") THEN EXIT; 
IF NOT ItemVendor.GET("Buy-from Vendor No.","No.") THEN EXIT;
IF FORMAT(ItemVendor."Lead Time Calculation") = '' THEN EXIT;

ExpOrder := CALCDATE(ItemVendor."Lead Time Calculation",PurchHeader."Order Date");
MESSAGE(Txt001,'%1',ExpOrder);

The same basic principle as in all code. Test first, then execute.

Thanks you Erik.