
private static server str getAmount()
{
str amount;
amount = SysComputedColumn::returnField(tablestr(ABC_SalesInvoiceLinesListView), tableStr(InventTrans), tableMethodStr(InventTrans, lineAmount));
return amount;
}
Hii,
In D365FO, you cannot directly use a display method from a table in a view’s computed column. This is because display methods are written in X++ and executed on the application layer, whereas views are executed in SQL Server, which cannot interpret X++ code.
As a result, display methods are not SQL translatable and cannot be used inside computed columns of views. The correct approach is to replicate the logic of the display method using SQL compatible functions provided by the SysComputedColumn class
You need to create a static server method in the view that returns a SQL expression using functions like SysComputedColumn::returnField() to fetch fields, SysComputedColumn::if() for conditional logic, and arithmetic functions like multiply(), add(), or divide() as needed. This static method is then assigned to the computed column in the view. Essentially, instead of calling the display method, you reproduce its logic in a way that SQL Server understands. This ensures that the view compiles and runs correctly without any runtime issues.
Sample code:
private static server str remainAmountCur()
{
return SysComputedColumn::subtract(
SysComputedColumn::returnField(tableStr(DT_CustTransView), identifierStr(CustTrans), fieldStr(CustTrans, AmountCur)),
SysComputedColumn::returnField(tableStr(DT_CustTransView), identifierStr(CustTrans), fieldStr(CustTrans, SettleAmountCur))
);
}
Let me know if you'd like help converting a specific display method into a computed column.