AX – D365FO – Change Background or text color of a Form grid row using Extensions

You can use FormDataSource.displayOption method

This method is executed one time for each record before the record is displayed in a form.

This is an example on how to change the backcolor of a row grid at Form DataSource level using Extensions

[ExtensionOf(formdatasourceStr(Salestable, SalesLine))]
final class OTS_SalesLine_SalesTableFormDS_Extension
{

public void displayOption(Common _record, FormRowDisplayOption _options)
{
next displayOption(_record, _options);
FormRealControl ots_SalableStockQty = this.formRun().design().controlName(formControlStr(SalesTable, ots_salableStockQty));

int underSafetyStockColor   = WinApi::RGB2int(255,250,205);
_options.backColor(underSafetyStockColor);
        _options.affectedElementsByControl(ots_SalableStockQty.id());
}
}

Leave a comment