General X++ Development

How do I execute code when a form opens in D365FO?

Asked by Sunny Vasty· Aug 13, 2026· 1 answers

How do I execute code when a form opens in D365FO?

SSunny Vasty75 reputation · answered Aug 13, 2026

Extend the form's init() method when the logic is form-level.

X++
[ExtensionOf(formStr(MyForm))]
final class MyForm_Extension
{
    public void init()
    {
        next init();

        // Your initialization logic.
    }
}

If what you are initializing belongs specifically to a datasource, put the logic on the datasource instead. Keeping logic close to what it affects makes the form a lot easier to maintain.