Monday, November 13. 2006Using "nofetch" in X++ select statementsAxapta inherently begs community involvement from X++ developers due to its horrible lack of documentation. Dynamics Ax 4.0 (the erp system formerly known as..) certainly solves this to great lengths, but there are still grey-areas here and there which need to be filled in. I often get asked about tips and tricks in Axapta, and today I was asked (again) about the nofetch keyword in X++ select statements. Why is it there? What's the point? Simply put, this keyword is designed to set up a select statement with results that are used elsewhere. The idea is that you can run a null operation select statement, pass on the cursor, and another part of your program can use this cursor to actually do the work with the cursor. This seems somewhat pointless until you start to really dig into using datasources within reports and forms. This all boils down to efficiency. Why bother making a call to the database twice? The nofetch keyword helps you avoid (wasteful) calls to the database. The real power of this comes about when you need to write a query, especially for reports, where what you need to express can more efficiently be done using an X++ select statement rather than a configured query object. This is the familiar solution where the query object becomes impossible to use, because let's face it, sometimes they are just too procedural. Let me give you an example so you can see what's happening here. I'll use a form to illustrate my example since they're very familiar. What we're planning on doing here is replacing the default query that is built when the form is initialised with our own select statement. The form will effectively run its query off our select statement, rather than a configure query object. Let's create a form with a datasource; I've used CustTable in my example. Add a grid control with customer numbers and names so you can see the result set. To stop the default query from being built, change the AutoQuery property on the CustTable datasource to No. Override the datasource method init() on the CustTable datasource with the following code:
If you're too lazy to put the form together yourself, I have a little example you can try. Trackbacks
Trackback specific URI for this entry
|
Calendar
Creative Commons |