0

In a form like LedgerJournalTransDaily, there is a field Txt imported from LedgerJournalTrans. Using the JournalNum, I need to go to LedgerJournalTable and get the Name field.

I've written a display method like follows:

[SysClientCacheDataMethodAttribute(true)]
public display Name GetLedgerJournalTableName()
{
   LedgerJournalTable ledgerJournalTable;
   Name ret;

   select firstFast firstOnly ledgerJournalTable
       where ledgerJournalTable.JournalNum == this.JournalNum;

   ret = ledgerJournalTable.Name;

   return ret;
 }

To be honest, I am not sure if this is fast enough or if there is another way to do it. Please give me a hint.

Olaru Mircea
  • 2,570
  • 26
  • 49
  • 2
    The function body should be a one-liner: `return LedgerJournalTable::find(his.JournalNum).Name;` – Jan B. Kjeldsen Dec 03 '15 at 18:05
  • @JanB.Kjeldsen thanks, i am starting to get the point of this one-liners.. – Olaru Mircea Dec 04 '15 at 07:17
  • @JanB.Kjeldsen I don't necessarily agree, If performance is key a `select firstFast firstOnly name from ledgerJournalTable where ledgerJournalTable.JournalNum == this.JournalNum;` with an index on journalnum and name as an included column could make sense as you can turn it into a field select. That's paying for performance with readability coins though – Tom V Dec 04 '15 at 09:04
  • AX ignores your field list anyway as this select is the target of single-record caching. It is not explicitly stated, but when the select can be cached, it does not make sense not to cache all fields. See https://msdn.microsoft.com/en-us/library/bb314693.aspx – Jan B. Kjeldsen Dec 04 '15 at 09:51
  • 2
    For another explanation of what @JanB.Kjeldsen mentions, see [When fields lists don't work as expected](http://sashanazarov.blogspot.de/2015/10/when-fields-lists-dont-work.html) by Sasha Nazarov. Also related: [Select Statement Vs Find in Ax](http://stackoverflow.com/questions/27163459/select-statement-vs-find-in-ax) – FH-Inway Dec 04 '15 at 16:09

2 Answers2

2

If performance is a concern, you could try to add the LedgerJournalTable as read only datasource to the form with OnlyFetchActive = Yes, join it with the LedgerJournalTrans data source and add the Name field of the new data source to the form design.

But if the journals do not have hundreds of lines and there is no performance problem yet, I would go with the display method. You can always change it later if it becomes a problem and a display method is less invasive than a new data source.

For further reading, take a look at Tutorial: Caching display methods by Ivan Kashperuk.

FH-Inway
  • 4,432
  • 1
  • 20
  • 37
0

You can optimize it by moving select part to static server method on table and when you are selecting define fields you actualy need.

public static server Name getJourName... ... select Name from ledgerJournalTabel ...

And also you can set false in cache atribute parameter because journal number does not change for transactions in most cases.

Anže Krpič
  • 265
  • 1
  • 4
  • The server method will not buy you anything in this case, as it would defeat client side caching. That is why `find` methods should *not* use the`client` keyword. – Jan B. Kjeldsen Dec 04 '15 at 07:52
  • You should still use display method with caching. But in this method you can call your static server method. 'Find' methods return entire record and with display methods this is not needed. – Anže Krpič Dec 04 '15 at 15:31