Options

xmlport date returns 2020 instead 2018

catiamatos1991catiamatos1991 Member Posts: 158
edited 2018-11-14 in NAV Three Tier
Hi everyone, something really strange is happening with my xmlport.

From one moment to another, the date read from a file is "2020" instead of "2018" and the field "Ending Date" of my previous record can't be calculated (this field is equal to the last starting date - 1 day).

So I have a text file with the info below

1010100002 11/11/2018 0 11,95 (item no | starting date | quantity | price)

and the idea is to fill the Sales Price table with this information using my dataport with the following code
Sales Price - Import::OnBeforeInsertRecord()
nRecNum += 1;
dlgProgress.UPDATE(3, nRecNum);

"Sales Price".RESET;
"Sales Price".SETRANGE("Sales Price"."Item No.",PRODUTO); 
"Sales Price".SETRANGE("Sales Price"."Sales Type",1);
"Sales Price".SETRANGE("Sales Price"."Sales Code",'ALL');
"Sales Price".SETRANGE("Sales Price"."VAT Bus. Posting Gr. (Price)",'NAC');
"Sales Price".SETRANGE("Ending Date",0D); 
"Sales Price".SETRANGE("Currency Code",''); 
"Sales Price".SETRANGE("Variant Code",'');
"Sales Price".SETRANGE("Unit of Measure Code",'');
//"Sales Price".SETRANGE("Minimum Quantity",QT)

DataInicioText:=COPYSTR(DATAINI,1,8);
dia := COPYSTR(DataInicioText,1,2);
mes := COPYSTR(DataInicioText,4,2);
ano:= COPYSTR(DataInicioText,7,4);

MESSAGE('ano %1',ano);
MESSAGE('data %1',DataInicioText);
EVALUATE(DataInicio,dia+mes+ano);

"Sales Price".SETRANGE("Starting Date",DataInicio);

"Sales Price"."Starting Date":=DataInicio;

"Sales Price"."Item No.":=PRODUTO;
"Sales Price"."Allow Invoice Disc." :=TRUE; 
"Sales Price"."VAT Bus. Posting Gr. (Price)":='NAC'; 
"Sales Price"."Allow Invoice Disc.":=TRUE;

"Sales Price"."Sales Code":='ALL';
"Sales Price"."Sales Type":=1;
"Sales Price"."Currency Code":='';
"Sales Price"."Variant Code":='';
"Sales Price"."Ending Date":=0D;

"Sales Price".VALIDATE("Sales Price"."Sales Code",'ALL');
"Sales Price".VALIDATE("VAT Bus. Posting Gr. (Price)",'NAC');

Item.GET(PRODUTO);
"Sales Price"."Unit of Measure Code":=Item."Base Unit of Measure";


//Quantity

Quantity:=FORMAT(QT); 
EVALUATE("Sales Price"."Minimum Quantity",Quantity);

//Unit Price

Price:=FORMAT(PVP); 
EVALUATE("Sales Price"."Unit Price",Price);

//Unit Price with vat

VATPercentageProd:=Item."VAT Prod. Posting Group";
VATPercentageBus:=Item."VAT Bus. Posting Gr. (Price)";
VATPostingSetup.GET(VATPercentageBus,VATPercentageProd);
VATPerCent:=VATPostingSetup."VAT %";

EVALUATE(PriceVAT,PVP);
"Sales Price"."Unit Price Including VAT":=ConvertPriceToVAT(VATPerCent,PriceVAT);
 
IF NOT "Sales Price".INSERT(TRUE) THEN BEGIN
  "Sales Price".NEXT(-1);
  "Sales Price"."VAT Bus. Posting Gr. (Price)":='NAC';
  "Sales Price"."Ending Date":=DataInicio-1;
  "Sales Price".MODIFY(TRUE);
END;


And this xmlport is used in page 31 (item list) in a page action which have the property "RunObject" with "XMLport ImportTabPrecos".

Anyone can understand this strange thing?

Answers

  • Options
    ftorneroftornero Member Posts: 522
    Why do you do this:
    EVALUATE(DataInicio,dia+mes+ano);
    

    If you want get the date from a day, moth and year you must use this:
    DataInicio := DMY2DATE(dia, mes, ano);
    
  • Options
    vaprogvaprog Member Posts: 1,118
    edited 2018-11-13
    Pay attention to this line:
    DataInicioText:=COPYSTR(DATAINI,1,8);
    
    It actually cuts off the '18' at the end of 11/11/2018, which you gave as an example of your input.
    ftornero wrote: »
    If you want get the date from a day, moth and year you must use this:
    DataInicio := DMY2DATE(dia, mes, ano);
    

    This will actually not work like this because DMY4Date expects integers, not strings, as parameters. But anyway, it is the right function if you need to reassemble your date.

    Alternatively add in your local separator in the string you EVALUATE, or better, still, make it locale independent by doing
    EVALUATE(DataInicio,ano+'-'+mes+'-'+dia,9);
    
    i.e. creating a date string in the ISO format and evaluating it using the XML option. You need the 4-digit version of the year for this to work.
  • Options
    catiamatos1991catiamatos1991 Member Posts: 158
    edited 2018-11-14
    Right, thanks a lot. It worked. But the field "Starting date" of the previous record should be filled with a date also. In this case should have the value 12-11-2018 (Starting Date readed from file- 1);

    But my problem now is I tried this code
    IF "Sales Price".INSERT(TRUE) THEN BEGIN
      "Sales Price".RESET;
      IF "Sales Price".FINDLAST THEN BEGIN
         MESSAGE('data 1 %1 ',"Sales Price"."Starting Date");
        "Sales Price".NEXT(-1);
        MESSAGE('data 2 %1 ',"Sales Price"."Starting Date");
        "Sales Price"."Ending Date":=DataInicio-1;
        "Sales Price".MODIFY(TRUE);
      END;
    

    But the previous record is not being modified... And the message shows the a wrong previous record like the image below...

    gqfzqin6ahk4.png


    I need to fill the field Ending Date right next to the date 08-11-2018 to close the last product price.




    My idea is when inserting a new record I always need to fill the Ending Date of my previous record. If I'm modifyng a record already inserted in the system, the idea is to modify the existing record understand?
Sign In or Register to comment.