Tuesday, June 7, 2022

D365 FO Coloring records - Change grid row color in list page/form

 How to change grid row color in list page/ form in Dynamics  ?


Solution :

Go to Form Datasource and override Displayoption() method and write code according to your requirement.

The displayOption() method on any form's data source can be used to change some of
the visual options. Before displaying each record, this method is called by the system with
two arguments--the first is the current record and the second is a FormRowDisplayOption
object--whose properties can be used to change a record's visual settings just before it
appears onscreen. In this example, we check whether the current user is disabled, and if
they are, we change the background property to light red by calling the backColor()
method with the color code.

Example :

 public void displayOption(Common _record, FormRowDisplayOption _options)
{
    SalesTable prodtablelocal;
   
    prodtablelocal = _record;
   
    Switch(prodtablelocal.SalesStatus)
    {
    Case SalesStatus::Delivered:
    _options.backColor(WinAPI::RGB2int(255, 153, 255)); //Lime
 
    Break;
    Case SalesStatus::Invoiced:
    _options.backColor(WinAPI::RGB2int(#Red));
 
    Break;
    Case SalesStatus::Backorder:
    _options.backColor(65408); //Light Green
    //_options.affectedElementsByControl(Salestable_SalesId.id());
    _options.textColor(12582912);
    Break;
    }
}

Here is the result





No comments:

Post a Comment