zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    使用Layui上传图片,并进行压缩(非原创,证实可用)
    mysql 存储过程及事件
    Redis一些简单的笔记
    RIOT 技术笔记-01 RIOT介绍
    杂七杂八-ubuntu安装eclipse
    杂七杂八-sqlyog连接mysql错误码2058
    杂七杂八-Mysql8.0忘记root密码
    RIOT学习笔记-01 cygwin安装
    Ubutun-安装远程桌面
    中间件-RocketMQ 02 Docker下的安装
  • 原文地址:https://www.cnblogs.com/dingkui/p/6100745.html
Copyright © 2011-2022 走看看