Pages

February 24, 2019

Set background color for a field in form grid [DisplayOptionInitialize]

Hi Folks,

Today I am going to discuss how to make a filed text/background colorful :) This could be really helpful if you want to set such color based on an enum, like the status of the record or some kind of color coding on the grid based on an enum value. You can apply color on the entire grid line or one/more specific fields on the grid. So let's get started.

First, let's see how to achieve this using event handler. Assume there is field 'onHold' and you want to set vendor account no background/text to red or green based on this.  Go to your 'VendTable' form and vendTable data source and copy the event handler names 'DisplayOptionInitialize'. Paste this in a new class and write below code under this method (once you paste the event handler).
<CodeSample>


On new forms, the same can be achieved using overriding 'DisplayOption' method on the data source. Below code will give a hint


public void displayOption(Common _record, FormRowDisplayOption _options)
        {
            VendTable    vendTable = _record;

          //  _options.affectedElementsByField(<FieldName>);
            //    _options.backColor(<Color>);
            super(_record, _options);
        }
Please note, the color thing doesn't work when the user selects a record, it will make the selected line in default color setting. But useful when opening a grid and see the entire set of records.

See more..

Table Event handler methods in Dynamics 365 FO


Form Event handler methods in Dynamics 365 FO


Cheers!!!
-Harry Follow us on Facebook to keep in rhythm with us. https:fb.com/theaxapta

No comments:

Post a Comment

Thanks