How to SETFILTER by smallest order date

KnaaabisKnaaabis Member Posts: 7
I need to setfilter by MIN Production ending date like this:
ProductionOrderLine.SETFILTER(ProductionOrderLine."Ending Date",???)

Comments

  • BeliasBelias Member Posts: 2,998
    you need to get the minimum value of ending date, and THEN you can use it to filter the table...really strange request, imho

    prodorderline.setcurrentkey([a key that begins with ending date field]);
    prodorderline.findfirst;
    mindate := prodorderline."ending date";

    clear(prodorderline);
    prodorderline.setrange("ending date",mindate);
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • KnaaabisKnaaabis Member Posts: 7
    I haven't get right result... I will show you all code and maybe you integrate your code inside.


    ProductionOrderLine.RESET;
    ProductionOrderLine.SETCURRENTKEY(Status,"Item No.","Location Code");
    ProductionOrderLine.SETFILTER(Status,'%1..%2',ProductionOrderLine.Status::Planned,ProductionOrderLine.Status::Released);
    ProductionOrderLine.SETFILTER(ProductionOrderLine.Quantity,'>0');
    ProductionOrderLine.SETRANGE("Item No.",Item."No.");
    ProductionOrderLine.SETRANGE("Location Code", "Sales Line"."Location Code");
    IF NOT ProductionOrderLine.FINDFIRST THEN
    CLEAR(ProductionOrderLine);
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    You have to use a key which starts with ending date in SETCURRENTKEY
  • KnaaabisKnaaabis Member Posts: 7
    Like this?
    ProductionOrderLine.RESET;
    ProductionOrderLine.SETCURRENTKEY(Status,"Item No.","Location Code","Ending Date");
    ...
    but what next?
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    like this
    ProductionOrderLine.SETCURRENTKEY("Ending Date",Status,"Item No.","Location Code");

  • KnaaabisKnaaabis Member Posts: 7
    And what next?
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    prodorderline.findfirst;
    mindate := prodorderline."ending date";

    mindate date will have smallest ending date
  • KnaaabisKnaaabis Member Posts: 7
    Doesn't work... Please integreate in full code.
    In which place will be this?
    prodorderline.findfirst;
    mindate := prodorderline."ending date";

    That is full code.

    ProductionOrderLine.RESET;
    ProductionOrderLine.SETCURRENTKEY("Ending Date",Status,"Item No.","Location Code");
    ProductionOrderLine.SETFILTER(Status,'%1..%2',ProductionOrderLine.Status::Planned,ProductionOrderLine.Status::Released);
    ProductionOrderLine.SETFILTER(ProductionOrderLine.Quantity,'>0');
    ProductionOrderLine.SETRANGE("Item No.",Item."No.");
    ProductionOrderLine.SETRANGE("Location Code", "Sales Line"."Location Code");
    IF NOT ProductionOrderLine.FINDFIRST THEN
    CLEAR(ProductionOrderLine);
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    IF NOT ProductionOrderLine.FINDFIRST THEN
    CLEAR(ProductionOrderLine)
    ELSE
    mindate := prodorderline."ending date";

    Is it a report or where do you need minimum ending date?
  • KnaaabisKnaaabis Member Posts: 7
    It find date, but that isn't Min date - it's first date in table.
    For example - I have data in table like this:
    ......18.12.15
    ......19.11.15
    ......03.12.15
    Code find date 18.12.15, but should be 19.11.15
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    did you add above code after
    ProductionOrderLine.RESET;
    ProductionOrderLine.SETCURRENTKEY("Ending Date",Status,"Item No.","Location Code");
    ProductionOrderLine.SETFILTER(Status,'%1..%2',ProductionOrderLine.Status::Planned,ProductionOrderLine.Status::Released);
    ProductionOrderLine.SETFILTER(ProductionOrderLine.Quantity,'>0');
    ProductionOrderLine.SETRANGE("Item No.",Item."No.");
    ProductionOrderLine.SETRANGE("Location Code", "Sales Line"."Location Code");
  • KnaaabisKnaaabis Member Posts: 7
    Full Code:

    ProductionOrderLine.RESET;
    ProductionOrderLine.SETCURRENTKEY("Ending Date",Status,"Item No.","Location Code");
    ProductionOrderLine.SETFILTER(Status,'%1..%2',ProductionOrderLine.Status::Planned,ProductionOrderLine.Status::Released);
    ProductionOrderLine.SETFILTER(ProductionOrderLine.Quantity,'>0');
    ProductionOrderLine.SETRANGE("Item No.",Item."No.");
    ProductionOrderLine.SETRANGE("Location Code", "Sales Line"."Location Code");
    IF NOT ProductionOrderLine.FINDFIRST THEN
    CLEAR(ProductionOrderLine)
    ELSE
    mindate := ProductionOrderLine."Ending Date";



    If i add there "Ending Date" (ProductionOrderLine.SETCURRENTKEY("Ending Date",Status,"Item No.","Location Code");), then i get error message:
    "The Prod. Order Line table doesn't have an active key that starts with the following field or fields: Ending date, Status, Item No., Location Code."
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Please check whether there is a key already with Ending date or not
    if not then create One
Sign In or Register to comment.