Recently I posted a Trick to create a display method on sys Tables using overlaying. In further researches, due to necessity, I bumped into a new and more robust way of doing the same.
The purpose of this post is to explain a possibility to facilitate the manipulation of Table Methods on Augmented classes.
Augmented classes are necessarily Final classes defined by the use of the Attribute ExtensionOf on its declaration, in my example I’m augmenting the Table ProjForeCastOnAcc.
//Begin: Felipe Nogueira - AXAPTAHUT , Apr 9th 2018 | |
[ExtensionOf(tableStr(ProjForecastOnAcc))] | |
final class ProjForecastOnAcc_Extension | |
{ | |
} | |
//End: Felipe Nogueira - AXAPTAHUT , Apr 9th 2018 |
This allows us to interact with the class as if it were the actual table, So we have access to fields, methods, and properties from the original table.
I created this new display method on it, notice that at line ‘8’ of the following code, I’m mentioning one field from the original table by using the reserved word “this”, although the current object is not the actual table. All fields, methods, and properties from the original table can be accessed this way as if we were in the actual object.
//Begin: Felipe Nogueira - AXAPTAHUT , Apr 9th 2018 | |
[ExtensionOf(tableStr(ProjForecastOnAcc))] | |
final class ProjForecastOnAcc_Extension | |
{ | |
[SysClientCacheDataMethodAttribute] | |
public display ProjGrantName grantName() | |
{ | |
return ProjGrant::findByGrantId(this.ProjGrantId).GrantName; | |
} | |
} | |
//End: Felipe Nogueira - AXAPTAHUT , Apr 9th 2018 |
X++ Executing Table methods from Augmented classes
This feature allows us to access these new methods as if they were located in the original table wherever a buffer is created. The next code is a non-related Class making use of the new Display Method on the Augmented class, notice line 12 of the following code:
//Begin: Felipe Nogueira - AXAPTAHUT , Apr 9th 2018 | |
class ProjForecastOnAcc_Ext_Test | |
{ | |
static void main(args args) | |
{ | |
ProjForecastOnAcc forecastOnAcc; | |
while select forecastOnAcc | |
where forecastOnAcc.ProjGrantId | |
{ | |
info(strfmt("%1 - %2", | |
forecastOnAcc.ProjGrantId, | |
forecastOnAcc.grantName()));/*New method on ProjForecastOnAcc_Extension*/ | |
} | |
} | |
} | |
//End: Felipe Nogueira - AXAPTAHUT , Apr 9th 2018 |
Form usage of display methods from Augmented classes
The way of mentioning the extended methods on Forms is still the same as in the old trick. You must have the correct DataSource, then insert the full name of the Augmented Class together with the desired display method name to the field’s property “Data Method”, like this:
- DataSource: ProjForecastOnAcc
- DataMethod: ProjForecastOnAcc_Extension::grantName
If done correctly, this solution should work without any issues.
Follow us and get exclusive AX DEV content weekly
Hope it might be helpful,
Thanks,
Felipe Nogueira