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.
0
Comments
Thanks.
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.
Thanks.
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.
Thanks.
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
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 none of my suggestens match your problem, please try to explain with an example.
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.
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.
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.
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.
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.
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. 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".
Thanks for your time.
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.
Thank you very much for your help and time, you helped me a lot.