AX7: HOW TO USE TABLE METHOD EXTENSION CLASS

To create new methods on a table without customize you should use the Table method extension class. This class will be compiled as an extension of the original table and the methods will be serialized to be included as part of the table methods.

First create a new class like below. Use the name pattern “YourClassName” + “_Extension“. On the example I will use the SalesLine table.

1
2
3
4
public static class MySalesLine_Extension
{
 
}

Create your method always as Public Static and the first parameter should always be the table (It’s by this parameter and the “_Extension” that the builder will understand that the class is a “method extension class”). After that you can provide your parameters as you normally do and you can use when you gonna call the method.

1
2
3
4
5
6
7
public static class MySalesLine_Extension
{
    public static void initSalesLineCustom(SalesLine _this)
    {
        _this.ReceiptDateRequested = today();
    }
}

After build your project and sync your database, this new method will be available to be used as part of the SalesLine table.

 

1
2
3
4
5
SalesLine salesLine;
 
select firstonly salesLine;
 
salesLine.initSalesLineCustom();

Important:

  • Display methods doesn’t work on class extension.
  • Static methods like “Find” that we used on AX2012 will be normal table methods now, so you need to declare the variable for the table and use the “find” as a normal method. Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public static class MySalesLine_Extension
{
    public static SalesLine findByRecId(SalesLine _this,
                                        RecId     _recId,
                                        boolean   _forupdate = false)
    {
        SalesLine salesLine;
 
        if (_forupdate)
        {
            salesLine.selectForUpdate(_forupdate);
        }
 
        select firstonly salesLine
                where salesLine.RecId == _recId;
 
        return salesLine;
    }
}

And use the find like on the code below:

1
2
3
SalesLine salesLine;
 
salesLine = salesLine.findByRecId(salesLineRecId);
posted @   adingkui  阅读(424)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2013-11-25 AX2009 连接外部Orcal与SQL区别
点击右上角即可分享
微信分享提示