D365/AX7:OnDisplayOptionInitialize event is retrieving/getting always the first record

Purpose

I have posted sample code of customisation for adding color to a form control of a standard or custom form by using event OnDisplayOptionInitialize.

D365/AX7:Adding color to a form control of a standard or custom form by using event OnDisplayOptionInitialize

But there is issue in above method of customisation i.e OnDisplayOptionInitialize event is retrieving/getting always the first record when you will do conditional coloring.

Sample Code & Solution

This code is working fine on version 8.1 or higher and PU 20 or higher.The code is not working on version 7.3.

Instead of using sender.cursor(),

use eventArgs.record()

Otherwise color will come only on that record where cursor is placed.

[code language=”cpp”]/// /// /// /// /// ///
[FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::DisplayOptionInitialize)]
public static void SalesLine_OnDisplayOptionInitialize(FormDataSource sender, FormDataSourceEventArgs e)
{
SalesLine salesLine //= sender.cursor(); wrong
FormDataSourceDisplayOptionInitializeEventArgs eventArgs = e as FormDataSourceDisplayOptionInitializeEventArgs;
salesLine = eventArgs.record(); //correct
if (salesLine.ItemId == ‘1105’)
{
//eventArgs.displayOption().affectedElementsByControl(sender.formRun().design(0).controlName(“ItemName”).id())
eventArgs.displayOption().textColor(WinAPI::RGB2int(255,0,0));
}
else
{
//eventArgs.displayOption().affectedElementsByControl(sender.formRun().design(0).controlName(“ItemName”).id());
eventArgs.displayOption().textColor(WinAPI::RGB2int(255,255,0));
}
}
[/code]

 

 

 

 

 

One thought on “D365/AX7:OnDisplayOptionInitialize event is retrieving/getting always the first record”

Leave a Reply