Thursday, 27 August 2026

How to Access Extension Fields Dynamically in D365FO Without a Model Reference

In D365FO, sometimes a field is added through an extension in another model, but your current model cannot reference that model because of package/model dependency restrictions.

The problem is that you cannot directly access the field:

_salesTable.Custom_Field

But if you still need to read this field for data manipulation or customization, you can access it dynamically using DictTable.

Solution

public static str getExtensionFieldValue(SalesTable _salesTable)
{
    Common      commonRecord;
    DictTable   dictTable;
    FieldId     fieldId;
    str         fieldName = 'Custom_Field';
    str         fieldValue;

    dictTable = new DictTable(tableNum(SalesTable));
    fieldId = dictTable.fieldName2Id(fieldName);

    commonRecord = _salesTable as SalesTable;

    if (fieldId)
    {
        fieldValue = commonRecord.(fieldId);
    }

    return fieldValue;
}

How It Works

The code uses DictTable to find the FieldId of Custom_Field without creating a direct compile-time reference to the field.

fieldId = dictTable.fieldName2Id(fieldName);

Once the FieldId is available, the field value can be retrieved dynamically:

fieldValue = commonRecord.(fieldId);

You can then use the value in your customization:

if (getExtensionFieldValue(_salesTable) == 'Yes')
{
    // Custom logic
}

Conclusion

When a model cannot reference another model containing a table extension, dynamic field access using DictTable can be a practical way to read the extension field and continue with your required customization—without changing the existing model dependency.

No comments:

Post a Comment

How to Access Extension Fields Dynamically in D365FO Without a Model Reference

In D365FO, sometimes a field is added through an extension in another model, but your current model cannot reference that model because of ...