PDA

View Full Version : API & Dates



Bob Worsley
7-Mar-2010, 02:24 PM
I've been working with RC II and the API, and have been attempting to get a date range to work. I thought it was working until I created a new report with a different table and now I can't get the filter to work at all - I just get all data. What I started with is:


Move (sFormat("({TSHead.Start_Date} = dateserial(%1,%2,%3))", DateGetYear(dFromTslinesDate), DateGetMonth(dFromTslinesDate),DateGetDay(dFromTsl inesDate))) to sFilterFunction
Move (sFilterFunction * 'and' * (sFormat("{TSHead.End_Date} <= dateserial(%1,%2,%3))", DateGetYear(dToTslinesDate), DateGetMonth(dToTslinesDate),DateGetDay(dToTslines Date)))) to sFilterFunction
Set psFilterFunction to ('return '+sFilterFunction)
And when I couldn't make that work I hard coded the date:


Move ('TSHead.Start_Date = "02/08/2010"') to sFilterFunction
Set psFilterFunction to ('return '+sFilterFunction)
And I still get all data. If the filter was actually doing something and the syntax incorrect, I'd expect to get nothing back. What am I doing wrong? All of the above is being done in OnInitializeReport per the guide.

Bob Worsley
7-Mar-2010, 07:07 PM
Update...

If I add the following to the Filter Function in VRW I get the correct data retrurn I would expect.


return ({TSHEAD.START_DATE} <= DateSerial(2010,2,14)) and ({TSHEAD.END_DATE} >= DateSerial(2010,2,8)))


Hard coding psFilterFunction in the API to the above gets me all data.

Vincent Oorsprong
8-Mar-2010, 12:53 AM
Bob,

You've found the right way (use DateSerial()) to work with dates.

Note: In RC III the cVisualReport class will have a VRWDate function that does this work for you.

Bob Worsley
8-Mar-2010, 08:46 AM
I may have found the "right way" to do it, but in the API I can't make it actually work...

Vincent Oorsprong
8-Mar-2010, 02:10 PM
Bob,

Please show what you have put in psFilterString.

Bob Worsley
8-Mar-2010, 03:14 PM
Bob,

Please show what you have put in psFilterString.
Did you mean psFilterFunction? Or have I got it wrong? If psFilterFunction, see the earlier messages in the thread. I'll check psFilterString when I get back to the office. If I've got that wrong, that would go a long way toward explaining the problem...

Update - Nothing in the user guide on psFilterString...

Vincent Oorsprong
9-Mar-2010, 01:09 AM
Bob,

Sorry, my mistake. It is indeed psFilterFunction. So, what do you have in the code?

Bob Worsley
9-Mar-2010, 08:41 AM
See the first posting in this thread, I included the code there.

Vincent Oorsprong
9-Mar-2010, 10:30 AM
Bob,

I did a test and used the following code which works fine:


Object oReport is a cVisualReport
Set Size to 233 397
Set Location to 5 5
Set peAnchors to anAll
Set psReportName to "orders.vrw"
Set psFilterFunction to "return (({orderhea.order_date} >= DateSerial (2004,1,1)) And ({orderhea.order_date} <= DateSerial (2004,4,1)))"
End_Object

Bob Worsley
9-Mar-2010, 11:15 AM
Hmmmm... the user guide says to put it into OnInitializeReport. I was wondering if it might be a timing issue of some kind, but adding it to the object itself isn't a good thing, IMHO. If OnInitializeReport isn't a good place, is there an earlier event we should be using?

Or maybe just put it before Forward Send OnInitializeReport instead of after?

Vincent Oorsprong
9-Mar-2010, 12:49 PM
Bob,

I've made some changes in this area too in cVisualReport for the next release candidate.

Set psFilterFunction outside the OnInitializeReport is a supported way. Adding an event only for this is not needed.

I am only trying to figure out if and how I can avoid that people do things that should not be done, but maybe I should simply accept that when one puts garbage-in he should expect garbage-out...

Bob Worsley
9-Mar-2010, 01:12 PM
I am only trying to figure out if and how I can avoid that people do things that should not be done, but maybe I should simply accept that when one puts garbage-in he should expect garbage-out...
GIGO - one of my favorite acronyms. Though in this instance I think it's more timing than GIGO.

I'll experiment a bit with placement of the code. Thanks for the help.

Bob Worsley
9-Mar-2010, 08:42 PM
Bob,

I did a test and used the following code which works fine:


Object oReport is a cVisualReport
Set Size to 233 397
Set Location to 5 5
Set peAnchors to anAll
Set psReportName to "orders.vrw"
Set psFilterFunction to "return (({orderhea.order_date} >= DateSerial (2004,1,1)) And ({orderhea.order_date} <= DateSerial (2004,4,1)))"
End_Object

Yup, that does work. The problem is that it isn't terribly great for setting variables at runtime.

At a minimum, the documentation is wrong, at least for what I'm doing:



Object oReport is a cVisualReport
Set psReportName to 'MyReport.vrw'
Procedure OnInitializeReport
Forward Send OnInitializeReport
Set psFilterFunction to ‘return {Titles.YearPublished} = 1984’
End_Procedure
End_Object
And unfortunately I took it as being correct and didn't dig deeper. :rolleyes: On doing so the fix might be simple. In cVisualReport.pkg if you simply reverse the calls to onInitializeReport and the setting of the ComFilterFunction as follows, it works as expected. What would that break?


If (bOk) Begin
Send OnInitializeReport
Get pbCanceled to bCanceled
If (bCanceled) Begin
Move False to bOk
End
End

If (bOk) Begin
Get psPrivateFilterFunction to sFilterFunction
If (sFilterFunction <> "") Begin
Set ComFilterFunction iReportId to sFilterFunction
End
End

Vincent Oorsprong
10-Mar-2010, 01:03 AM
Bob,

You can temporarily make that change. But be aware we make changes too for RC III.

Bob Worsley
10-Mar-2010, 08:24 AM
Bob,

You can temporarily make that change. But be aware we make changes too for RC III.
Understood. Since in the original code you are calling the ComFilterFunction before OnInitializeReport where the User Guide recommends that psFilterFunction be set, what is the likelihood that you might adopt my fix which simply reverses the order and makes the process recommended in the doc work?

Bob Worsley
11-Mar-2010, 08:54 AM
So I take it you don't consider this a bug?