Changing a report's ranges automatically via X++

lee
Member Posts: 14
Hello. I'm Lee and I've been using Axapta at work for about 2 months now. I like it very much but am having a really hard time getting some good documentation and tutorials. Are there any popular ones out there ?
Currently I'm working on an automated daily report that runs via the batch. One of the criteria is that the date field of the table I am reporting on is the previous day from whenever the report is run. I.e. today()-1.
Obviously I can't enter this function as a criteria in the date range when the report is run or auto-run -- I can only enter a specific date or date range. So what I need is to modify this range via X++ in one of the report's functions before the report is run.
My first attempt was to override the report's init() function as follows:
public void init()
{
QueryBuildDataSource qbds;
QueryBuildRange qbr;
;
super();
//Change the date range to only list yesterday's calls.
qbds = Query.DataSourceTable(TableNum(MSM_SvcCallTable));
qbr = qbds.AddRange(FieldNum(MSM_SvcCallTable, LocalCloseDateStamp ) ) ;
qbr.value( date2str( today()-1,123,2,2,2,2,2 ) );
}
This fills in the date field OK but has a problem: When the day ticks over (simulated by changing my system clock) and the report is re-run, it still uses the previous value. Only by hitting the "reset" button for the criteria can I make it update the date again.
Is there a way to programmatically do this via X++?
Also, when I run the same report through a menu or menu item (i.e. instead of straight from the AOT), the date range does not show up at all.
Now I admit I'm a complete Axapta noob and am probably miles away from the correct way of doing this, but could anyone please provide me with a tidbit of advice to help me out ?
Thanks in advance
Lee.
Currently I'm working on an automated daily report that runs via the batch. One of the criteria is that the date field of the table I am reporting on is the previous day from whenever the report is run. I.e. today()-1.
Obviously I can't enter this function as a criteria in the date range when the report is run or auto-run -- I can only enter a specific date or date range. So what I need is to modify this range via X++ in one of the report's functions before the report is run.
My first attempt was to override the report's init() function as follows:
public void init()
{
QueryBuildDataSource qbds;
QueryBuildRange qbr;
;
super();
//Change the date range to only list yesterday's calls.
qbds = Query.DataSourceTable(TableNum(MSM_SvcCallTable));
qbr = qbds.AddRange(FieldNum(MSM_SvcCallTable, LocalCloseDateStamp ) ) ;
qbr.value( date2str( today()-1,123,2,2,2,2,2 ) );
}
This fills in the date field OK but has a problem: When the day ticks over (simulated by changing my system clock) and the report is re-run, it still uses the previous value. Only by hitting the "reset" button for the criteria can I make it update the date again.
Is there a way to programmatically do this via X++?
Also, when I run the same report through a menu or menu item (i.e. instead of straight from the AOT), the date range does not show up at all.
Now I admit I'm a complete Axapta noob and am probably miles away from the correct way of doing this, but could anyone please provide me with a tidbit of advice to help me out ?
Thanks in advance
Lee.
0
Comments
-
Hi Lee,
Welcome to this forum
As far as learning Axapta, please check my other posts on this topic.
For resetting the previous range, you might want to call clearRanges method like this -
qbds.clearRanges();
After this, try adding the range.
Hope this helps,Harish Mohanbabu
Long way to go before I sleep..0 -
I am sorry, but I don't see where the Query object gets filled.
I would think that this query is not connected to the report at all.
To do this you have to write a line like this:this.query(YourQuery);
And also, if Harish's advice to clear the ranges won't help, try using the YourQuery.reset() function.
Good luck in learning Axapta.Vanya Kashperuk,
My blog - http://kashperuk.blogspot.com
MorphX IT in Russian - http://www.lulu.com/content/723888
Inside Dynamics AX 4.0 in Russian - http://www.ozon.ru/context/detail/id/37145820 -
My understanding is that in the scope of the report's methods there is a special variable already declared called "Query" ? Of course, the Axapta documentation also tells me there is a special variable called "Report" but that doesn't seem to exist.kashperuk wrote:I am sorry, but I don't see where the Query object gets filled.
I would think that this query is not connected to the report at all.
To do this you have to write a line like this:this.query(YourQuery);
And also, if Harish's advice to clear the ranges won't help, try using the YourQuery.reset() function.
Good luck in learning Axapta.0 -
Yes, you are right. :shock:
This is something new that I learned today. Thanks
Sorry couldn't helpVanya Kashperuk,
My blog - http://kashperuk.blogspot.com
MorphX IT in Russian - http://www.lulu.com/content/723888
Inside Dynamics AX 4.0 in Russian - http://www.ozon.ru/context/detail/id/37145820
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions