X++ 运行 如何用于 D365 表格

How X++ run for D365 Form

在 D365 中,我知道如何 运行 为 DataSource、DataField 和 Control 编写代码。但是我如何 运行 为表单编码 "Run" "Init"?

如果我只是在Form层级下写"Run"和"Init"。它会自动 运行 吗? 或者,我需要一些方法来调用它们? 我怎样才能 运行 这个 "Run" 用于我的表单?

enter image description here

请阅读以下文档。它适用于 D365 表单 opening.You 可以覆盖此表单方法。 Event Method Sequences when a Form is Opened

好吧,您可以自己尝试使用像这样的简单测试表:

[Form]
public class TestForm1 extends FormRun
{
    void run()
    {
        info("test from run()");
        super();
    }
}  

如果你 运行 它你会看到消息出现。

与之前的版本 (2009/2012) 一样,如果您覆盖如下所示的方法,您可以只查看工具生成的代码:

如果您正在从头开始开发自定义表单,那么是的,正如@DAXaholic 指出的那样,您可以直接在表单上覆盖 runinit 方法,然后在那里实现您的自定义逻辑你在以前的 AX 版本中做过。

但是叠加很强烈discouraged in D365 and will no longer be supported by Microsoft. That means that if you are customizing a standard form or any other form which is not in the same package you have to use extensibility approach to implement custom logic. This can be achieved through extensions and event handlers

假设你有一个表单,你必须在表单初始化前后执行一些代码。您可以创建事件处理程序 class 并订阅 OnInitializingOnInitialized 事件,而不是覆盖对象和覆盖 init 方法:

[FormEventHandler(formStr(Test), FormEventType::Initializing)]
public static void Test_OnInitializing(xFormRun sender, FormEventArgs e)
{
    // your code here
}

[FormEventHandler(formStr(Test), FormEventType::Initialized)]
public static void Test_OnInitialized(xFormRun sender, FormEventArgs e)
{
    // your code here
}