-1

In D365, I know how to run code for DataSource, DataField, and Control. But How can I run code "Run" "Init" for Form?

If I just write "Run" and "Init" under the Form level. Will it run automatically? Or, I need some ways to call them? How can I run this "Run" for my Form?

enter image description here

Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50

3 Answers3

1

If you are developing a custom form from scratch then yes, as @DAXaholic has pointed out you can override run and init methods directly on your form and then implement your custom logic there as you did in previous AX versions.

However overlayering is strongly 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.

Suppose you have a form and you have to execute some code before and after the form is initialized. Instead of overlaying the object and overriding init method you can create an event handler class and subscribe to OnInitializing and OnInitialized events:

[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
}
Alex
  • 1,433
  • 9
  • 18
0

Please go through below docs. Its applicable for D365 form opening.You can override this form methods. Event Method Sequences when a Form is Opened

0

Well you could just try it yourself with a simple test form like this:

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

If you run it you will see the message appears.

As in previous editions (2009/2012) you can just look at the code the tooling would generate if you override the method as shown below:

Tooling

DAXaholic
  • 33,312
  • 6
  • 76
  • 74