Hello all!
I'm quite new to axapta development but I 've been developing in many
different environments and languages for about 15 years now. There are
some "universal" do's and dont's regardless of the environment or
programming language that I've lerned from day 1.
One of them says "Store the result of a resource - expensive operation
to a local variable when you need to access that result multiple times
within the same scope". This is why I was surprized when I saw the
following code inside a core Axapta table (VendInvoiceJour):
boolean interCompanyDoInternalPosting()
{;
return this.purchTable().InterCompanyDirectDelivery
&&
this.purchTable().interCompanyEndpointActionPolicy().PostSalesInvoice
&& !this.purchTable().ProjId;
}
This table method needs some information from the PurchTable record that
is related to the current VendInvoiceJour record. Now let's see what the
purchTable method does:
PurchTable purchTable(boolean update = false)
{
PurchTable purchTable = PurchTable::find(this.PurchId,
update);
PurchTableDelete purchTableDelete;
;
if (!purchTable && this.PurchId)
{
purchTableDelete = PurchTableDelete::find(this.PurchId);
if (purchTableDelete.PurchTable)
[purchTable] = purchTableDelete.PurchTable;
}
return purchTable;
}
Wow! That method contains two data access calls (PurchTable::find and
PurchTableDelete::find) and an unpack operation and it is called 3 times
in a row inside the first method just to read 3 fields from it's
returned record. I know that Axapta offers record caching but this still
looks terribly expensive to me. What I would expect to see would be:
boolean interCompanyDoInternalPosting()
{
PurchTable tPurch = this.PurchTable(); //Store the result of the
lookup to a local variable
;
return tPurch.InterCompanyDirectDelivery
&& tPurch.interCompanyEndpointActionPolicy().PostSalesInvoice
&& ! tPurch.ProjId;
}
The problem is that this is not an isolated insident. I've seen this
approach in many core Axapta codes. Am I missing something here? What's
your opinion?
[Non-text portions of this message have been removed]