0

What Is FormDataFieldStr?

FormDataFieldStr is a preprocessor macro in D365 X++ Development used to reference a form control that is bound to a specific field in a datasource. It allows developers to get a fully qualified string reference to a form control at compile time, for better maintainability and fewer runtime errors.

Syntax:

FormDataFieldStr(<FormName>, <DataSourceName>, <FieldName>)

Expands to:

<FormName>_<DataSourceName>_<FieldName>
X++ FormDataFieldStr D365 FinOps Dynamics Edge
X++ FormDataFieldStr D365 FinOps Dynamics Edge

This string corresponds to the name of the control generated for a bound data field in the form design, and is used especially in logic that accesses your controls programmatically.


Why It Matters in Chain of Command (CoC)

When extending forms using CoC (typically through event handlers or form extensions), you often need to access controls dynamically in your override or handler logic. FormDataFieldStr helps by giving you a reliable string name to use with the formRun.control() or formRun.design() APIs.

Example Use in CoC Extension:

[ExtensionOf(formStr(SalesTable))]
final class SalesTable_Extension
{
    public void init()
    {
        next init();

        FormControl control = this.design().control(FormDataFieldStr(SalesTable, SalesTable, CustAccount));
        if (control)
        {
            control.visible(false);
        }
    }
}

Here, FormDataFieldStr(SalesTable, SalesTable, CustAccount) refers to the CustAccount control in the SalesTable form’s main datasource. This ensures that you don’t hardcode control names.


Key Benefits

  • Compile-time validation: Prevents typos and mismatched control references.
  • Tooling support: Works with IntelliSense, making refactoring safer.
  • CoC-friendly: Ideal when working in extension layers, especially in restricted overlay-free environments like D365FO.

Code Example Inside Button Click Handler (Extension)

[FormControlEventHandler(formControlStr(MyForm, MyButton), FormControlEventType::Clicked)]
public static void MyButton_OnClicked(FormControl sender, FormControlEventArgs e)
{
    FormRun formRun = sender.formRun();
    FormControl control = formRun.design().control(FormDataFieldStr(MyForm, MyDataSource, MyField));

    if (control)
    {
        control.enabled(false);
    }
}

FormDataFieldStr vs FieldStr vs DataFieldStr

  • FieldStr(Table, Field)
    → Just returns "Field" as a string. Used mostly in queries, table buffers.
  • DataFieldStr(DataSource, Field)
    → Returns "DataSource_Field", often used within form logic, less context-aware than FormDataFieldStr.
  • FormDataFieldStr(Form, DataSource, Field)
    → Fully qualified string: "Form_DataSource_Field". Matches actual control names in the form’s design and best for use with formRun.control().

Brief Note on AX 2012

In AX 2012, FormDataFieldStr was also available and had similar use, but CoC didn’t exist yet. Instead, devs used event handlers or traditional overrides. In D365FO, FormDataFieldStr became even more useful as CoC demanded safe, string-based access to controls in extension scenarios.

Have a Question ?

Fill out this short form, one of our Experts will contact you soon.

Call Us Today For Your Free Consultation