Get last record stopped record

I have this dataport in nav 2009 and for new records in Sales Price table it isn't filling the field "Ending Date". I've the code (Findfirst) to that and with my debug it doens't enter there, even with a record

kd38g91zu6b8.png
Sales Price - OnAfterImportRecord()
"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("Starting Date",DATAINI);
"Sales Price".SETRANGE("Currency Code",'');
"Sales Price".SETRANGE("Variant Code",'');
"Sales Price".SETRANGE("Unit of Measure Code",'');
"Sales Price".SETRANGE("Minimum Quantity",QT);
"Sales Price".DELETEALL;

"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("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);

IF "Sales Price".FINDFIRST THEN BEGIN
     IF DATAINI< "Sales Price"."Starting Date" THEN
            "Sales Price".DELETEALL;
                      END;


"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("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);

IF "Sales Price".FINDFIRST THEN BEGIN
        "Sales Price"."Ending Date":=DATAINI-1;
        MODIFY;
END;
 
"Sales Price".RESET;
"Sales Price"."User ID":=USERID;
"Sales Price"."Data criacao":=TODAY;
"Sales Price"."Ending Date":=0D;
"Sales Price"."Sales Type":=1;
VALIDATE("Sales Code",'ALL');
"Item No.":=PRODUTO;
"Starting Date":=DATAINI;
"Minimum Quantity":=QT;
"Sales Price"."Allow Invoice Disc." :=TRUE;
"Sales Price"."VAT Bus. Posting Gr. (Price)":='NAC';
"Sales Price"."Allow Invoice Disc.":=TRUE;


       VALIDATE("Unit Price",PVP);

      // "Sales Price".INSERT;

My text file

1510300131 06-11-18 0 4,66

(itemno, starting date, quantity, price)







I've also tried this in OnInsert Sales Price trigger

IF xRec."Item No."<>'' THEN BEGIN
  Rec."Ending Date":=xRec."Starting Date"-1;
  MODIFY;
END;

Answers

  • KTA8KTA8 Posts: 204Member
    Rec."Ending Date":=xRec."Starting Date"-1;

    I don't see if it's a date something like that could work. You should use calcdate instead:
    https://docs.microsoft.com/en-us/dynamics-nav/calcdate-function--date-

  • catiamatos1991catiamatos1991 Posts: 123Member
    The problem itself is to don't fill this field sometimes and I can't figure why
  • vaprogvaprog Posts: 852Member
    edited 2018-11-09
    I would set a filter for "Starting Date" and then modify all found records, not just the first one
    ...
    "Sales Price".SETRANGE("Unit of Measure Code",'');
    "Sales Price".SETRANGE("Minimum Quantity",QT);
    
    // IF "Sales Price".FINDFIRST THEN BEGIN
    //         "Sales Price"."Ending Date":=DATAINI-1;
    //         MODIFY;
    // END;
    "Sales Price".SETFILTER("Starting Date",'<%1',DATAINI);
    "Sales Price".MODIFYALL("Ending Date",DATAINI-1,TRUE)
    
    ...
    

    ... also, if the quantity scale changes, you might be in trouble. But it is a tricky business to import prices unless what you import replaces what you already have entirely.
  • catiamatos1991catiamatos1991 Posts: 123Member
    I'm using a dataport understand? And I can't figure where to put the Ending Date calc (In a aftergetrecord trigger maybe).

    I tried to put a message in the "find last" function but it doens't pop up for some reason, and in this specific produtct I have multiple Sales Line lines.

    In the image below I have the text file i'm trying to import and the final result

    rjbf32bsp9f2.png
  • vaprogvaprog Posts: 852Member
    You filter on
    "Sales Price".SETRANGE("Unit of Measure Code",'');
    
    but the "Unit of Measure Code" of your old sales price line is UNI, and there is no unit of measure in your input file. So why do you expect to get a result different from what you got?

    The trigger you used, according to your first post, is ok (assuming that data item processes the import data).
  • catiamatos1991catiamatos1991 Posts: 123Member
    I understand @vaprog but my confusion is that this code, once worked in the past without any problems and also filled automatically the unit of measure code...
    So I need to remove all code from the dataport which don't exist in the text file? I'm confused
Sign In or Register to comment.