Get the filter on run a report

markyTmarkyT Member Posts: 120
Dear folks, I think thi is easy. I've a report that, on run, filter by "Order Date". I've a variable (called dateone that it's also a Date type) that shows a date. I need that, when filter on run the report buy "Order Date", the varible get also the filter that I've put and filter by it. How can I do that?.
Thanks in advance.

Comments

  • markyTmarkyT Member Posts: 120
    Any idea please?.
    Thanks.
  • rhpntrhpnt Member Posts: 688
    I think the lack of replies is due to the fact that we don't quite get what you want.

    I'll take a shot: put a SETRANGE/SETFILTER (look up the propper usage in NAV online help) in the OnPreDataItem trigger of the DataItem you want to filter.
  • vijay_gvijay_g Member Posts: 884
    look at this.
    dateone := dataitem.getfilter("Order Date");
    
  • markyTmarkyT Member Posts: 120
    Thanks. But if I put dateone := dataitem.getfilter("Order Date"); it say's me that one is Date typeand other txt type, but itsn't true, "dataone" variable is a date type one and also "Order date". What's the problem, please?.
    Thanks.
  • SLF25SLF25 Member Posts: 37
    Read what Navision help has to say about GETFILTER function, it's all there.
  • markyTmarkyT Member Posts: 120
    Thanks for help; but I can't get what I want. dateone := dataitem.getfilter("Order Date"); get the "order date", but doesn't filter by it.
    I'll try to explain it in detail:
    -I run the report and filter buy "Order date", and show me the orders filtered by it.
    -I also have a variable called "dateone" (Date type) that shows also a date.(This date is obtained with a calcdate instruction).
    -Some ordes haven't the "Order date" field informed, then, I want that get the "dateone" variable as it was the "Order date". Therefore, in this case, if I filter by "Order date" and it does not exist, automatically the report should get me the date indicated on "dateone" variable and filter the orders by it.
    I hope I have explained better, sorry for the confusion.
    Thanks in advance.
  • markyTmarkyT Member Posts: 120
    Does anybody knows how can I do it?
    Thanks.
  • vaprogvaprog Member Posts: 1,139
    markyT wrote:
    -I run the report and filter buy "Order date", and show me the orders filtered by it.
    -I also have a variable called "dateone" (Date type) that shows also a date.(This date is obtained with a calcdate instruction).
    -Some ordes haven't the "Order date" field informed, then, I want that get the "dateone" variable as it was the "Order date". Therefore, in this case, if I filter by "Order date" and it does not exist, automatically the report should get me the date indicated on "dateone" variable and filter the orders by it.
    What does your filter on "Order Date" look like? Assuming you set it to filter one specific order date, you won't find any documents with the "Order Date" not set (That is what I understand from "Some ordes haven't the "Order date" field informed")
    Then you say you precalculated your dateone variable. Why do you precalculate it if you want to overwrite it with the date filter value?

    Assuming you want to use dateone as a default value for orders that have "Order Date" blank just use
    dateone := CALCDATE(....);
    IF "Order Date = 0D THEN
      "Order Date := dateone;
    

    Assuming you want to use dateone as a default filter value for your report in case the user did not provide a filter on "Order Date" then use
    IF GETFILTER("Order Date") = '' THEN
      SETRANGE("Order Date",dateone);
    

    If none of my suggestens match your problem, please try to explain with an example.
  • markyTmarkyT Member Posts: 120
    Thanks for reply; I followed your codes and I've put the code:

    dateone:=CALCDATE(Item."Lead Time Calculation","Coming Date");
    IF ("Order Date"=0D)THEN BEGIN;
    IF GETFILTER("Order Date")='' THEN
    SETRANGE("Order Date",dateone);
    END;

    But it doesn't run. I've put it on "Purchase Line" body section. On run report, if dateone is 08/09/10 for example, on Order Date I put ..8/09/10 it appears (It's ok), if I put 7/09/10 it goes on appears (it's incorrect) but the strange is that if I put 8/09/10 (without ..) it doesn't appers. I think I left something, but the result is near. Do you know what's the problem please?
    Thanks for your help.
  • vaprogvaprog Member Posts: 1,139
    I still don't know what you are trying to achive!

    What is your SETRANGE statement supposed to do, especially when it is executed in a body section? and moreover, will it ever be executed given the conditions stated in your last posting?
    Did you understand how each of my code fragments work to achieve the assumption stated?

    However, given the filters you used are expedient, obviously both my assumptions are wrong.
  • markyTmarkyT Member Posts: 120
    Thanks for reply. Really sorry, because sure it's my fault, I don't explain well. I've undestand your code. I'll try to explain better. This part:

    dateone := CALCDATE(....);
    IF "Order Date = 0D THEN
    "Order Date := dateone;

    runs perfectly, the dateone variable shows the calculated date that I want, this part it's ok. And now, when, If I filter by an "Order Date" on run the report, if the "Order date" from a purchase order is in blank, the filter has to get the dateone date and show the purchase order if it is in Order date filter. I know that it should be the code:
    IF GETFILTER("Order Date") = '' THEN
    SETRANGE("Order Date",dateone);

    But it doesn't runs. It does nothing. I put all the code in "Purchase line" body section, but I've tested it in OnPreDataItem from "Purchase line" dataitem, but, on runs, it gave's me a date the error: can not be a date calculation based on an indefinite date, put what you put on "Order date" filter. I hope I've explained better.
    Thanks for your time and help.
  • vaprogvaprog Member Posts: 1,139
    markyT wrote:
    ... the filter has to get the dateone date and show the purchase order if it is in Order date filter ...
    The filter does not get anything. The filter takes effect only when the system retrieves a record from the database. this happens when you execute a FIND*, or NEXT statement, and in the case of a report the system executes an implicit next statement before the next OnAfterGetRecerd trigger is executed. Thus, the filter you set here in the body section only takes any effect for the record retrieved after the current one. Moreover, the SETFILTER statement overwrites the filter you set on the request form for the rest of the run of the report.
    markyT wrote:
    But it doesn't runs. It does nothing.
    You said you tried with the filter on "Order Date" set to ..8/09/10 and 7/09/10 and 8/09/10. None of these filters will cause
    IF GETFILTER("Order Date")='' THEN
      SETRANGE("Order Date",dateone);
    
    to do anything, since the condition is false. GETFILTER does not return any field value but the filter expression set on the field.

    Since I don't understand, what record you want to find with your filter (and why you need to find another record), I am unable to help you any further at this point.

    Please try to give us a desctiption of the business need such, that we could solve the part you struggle with. Plase give it from a customer's view, not from a programmer's view.
  • markyTmarkyT Member Posts: 120
    Thanks for reply. I honestly do not know how to explain it better, sorry, it's my fault.
    what record you want to find with your filter (and why you need to find another record)

    I need the "dateone" result variable, as it was the "Order date". I need it because there are sums in report, and purchasers want the "dateone" date in cases that "Order date" it's not put in the order.
    An archaid flowchart should be like this.

    Run the report
    |
    -¿put a filter on "Order Date"? - No - show all the orders
    -¿put a filter on "Order Date"? - Yes - ¿has purchase order the "Order date" informed and is on filter? - Yes - Show it
    -¿put a filter on "Order Date"? - Yes - ¿has purchase order the "Order date" informed? - No - get "dateone" and use it as it was the "order date" - ¿is dateone then on "Order date" filter? - Yes - Show it ¿is dateone then on "Order date" filter? - No - Don't show it.

    More or less it was the secuence. I don't know what else can explain.
    Thanks for your help.
  • vaprogvaprog Member Posts: 1,139
    Thanks, markyT, your flowchart makes things much more clear.

    Unfortunately there is no way known to me to apply a filter to a variable, not even the fields of a record variable, unless that record is insert into a table.

    If possible, you should try to make sure the "Order Date" gets set on entry. For orders already in the system you can set it with a processing report.

    If this, for some reason, is not possible, I suggest you copy the filters to a temporary record, insert the record you need to examine into the temporary table and try to find it again there.
    VAR
      PurchLineTemp@1000000000 : TEMPORARY Record 39;
    
    // OnPreDataItem
    PurchLineTemp.COPYFILTERS("Purchase Line");
    
    // OnAfterGetRecord
    IF "Order Date" = 0D THEN BEGIN
      dateone := CALCDATE(Item."Lead Time Calculation","Coming Date");
      PurchLineTemp := "Purchase Line";
      PurchLineTemp."Order Date" := dateone;
      PurchLineTemp.INSERT;
      IF NOT PurchLineTemp.FIND('=') THEN BEGIN
        PurchLineTemp.DELETE;
        CurrReport.SKIP;
      END ELSE
        PurchLineTemp.DELETE;
    END;
    
    This code will work regardless of whether a filter is set on "Order Date" or not. You coud skip the assign-insert-find-delete part though, if no filter is set on "Order Date".
  • markyTmarkyT Member Posts: 120
    Thank you very much indeed for your help. One question, I put the code OnAfeterGetRecord but it shows me the error "There is a sintactyc error", but it shows me line by line, is like this code could not be in this trigger. Any idea please?.
    Thanks for your time.
  • vaprogvaprog Member Posts: 1,139
    The code is tested and copied over from NAV. There is no syntactic error in the posted code.
    The code in the first box is taken off the text export of the object. Obviously you need to define the variable in the table for global variables.
    The code in the second box goes to the OnPreDataItem of the "Purchase Line" data item. You might place it in the OnAfterGetRecord trigger also, but executing it once should be enough.
    The code in the third box goes to the OnAfterGetRecord of the "Purchase Line" data item.

    If code is in a trigger where it cannot be executed you will not receive a compiletime error, but a runtime error.

    Please check code before and after in the trigger where NAV places the cursor. If this depends on where the cursor was when you initiated the compile, your error is most likely somewhere on the request form. Open it and recompile to find it.
  • markyTmarkyT Member Posts: 120
    Great!!!, =D> it works perfectly, as you said the problem was:
    Please check code before and after in the trigger where NAV places the cursor. If this depends on where the cursor was when you initiated the compile, your error is most likely somewhere on the request form. Open it and recompile to find it.

    Thank you very much for your help and time, you helped me a lot.
Sign In or Register to comment.