Showing posts with label clean code. Show all posts
Showing posts with label clean code. Show all posts
Monday, November 30, 2015
Tuesday, October 27, 2015
When fields lists don't work as expected
Did you know that a field list in a single-record select-statement is not always beneficial in comparison to a select firstonly * from... (or a static find-method)?
The thing is, when a where-clause matches a unique index (in AX 2009 – a primary index), the AOS may find the complete record in the cache and return it. And if this is the very first call, it will pull the whole record anyway, in order to be able to cache it. This may be proved by debugging.
So please use find-methods where possible, because they are easier to read and maintain. And remember: a while select with a nested find-method call may actually perform better than a join – thanks to caching. Therefore do measure performance to confirm that your select-statement is the most optimal one.
The thing is, when a where-clause matches a unique index (in AX 2009 – a primary index), the AOS may find the complete record in the cache and return it. And if this is the very first call, it will pull the whole record anyway, in order to be able to cache it. This may be proved by debugging.
So please use find-methods where possible, because they are easier to read and maintain. And remember: a while select with a nested find-method call may actually perform better than a join – thanks to caching. Therefore do measure performance to confirm that your select-statement is the most optimal one.
Tuesday, June 2, 2015
Which query range should I select?!
Customer asked me to figure out which "Customer account" should be selected in a query. There were three of them on the Customer invoice journal table:
Apparently, there were a couple of fields that used the default label, and I found them in the following way.
Selected the first "Customer account" range:
... right-clicked in the field value and selected Record Info:
... in the dialog, clicked on the Script button:
... pasted the clipboard to Notepad:
The extended field ID was 65540.
Then, I selected another range:
... and repeated the process. The second field ID was 81625. Finally, I selected the third Customer account range and found that it was based on the field ID 81626.
So, the three field IDs for CustInvoiceJour table were found. But what were the field names?
And the output was:
Somebody did not follow the Best Practices for Table Fields:
Apparently, there were a couple of fields that used the default label, and I found them in the following way.
Selected the first "Customer account" range:
... right-clicked in the field value and selected Record Info:
... in the dialog, clicked on the Script button:
... pasted the clipboard to Notepad:
The extended field ID was 65540.
Then, I selected another range:
... and repeated the process. The second field ID was 81625. Finally, I selected the third Customer account range and found that it was based on the field ID 81626.
So, the three field IDs for CustInvoiceJour table were found. But what were the field names?
static void printFieldNames(Args _args) { print fieldId2Name(tableNum(CustInvoiceJour), fieldExt2Id(65540)); print fieldId2Name(tableNum(CustInvoiceJour), fieldExt2Id(81625)); print fieldId2Name(tableNum(CustInvoiceJour), fieldExt2Id(81626)); pause; }
And the output was:
Somebody did not follow the Best Practices for Table Fields:
Subscribe to:
Posts (Atom)