Compute &Virtual fields recap in Microsoft Dynamics 365 Finance and Operations apps
Compute &Virtual fields recap in Microsoft Dynamics 365 Finance and Operations apps
Use care scenarios for getting ModifiedDateTime field from table to data entity using extensions
Getting inventory dimension values e.g. warehouse/site on entity
Virtual field (best for writes)
- A non-persisted field.
- Controlled by custom X++ code.
- Read and writes occur through custom X++ code.
- Typically used for intake values that are calculated by using X++ code and can't be replaced by computed columns
- Slows performance as it is done row by row
Computed field (best for read, display)
- The value is generated by an SQL view computed column.
- Recommended option for better performance
- During reads, data is computed by SQL and fetched directly from the view.
- For writes, custom X++ code must parse the input value and then write the parsed values to the regular fields of the data entity. The values are stored in the regular fields of the data sources of the entity.
- Used mostly for reads.
- It's a good idea to use computed columns instead of virtual fields whenever you can, because computed columns are computed at the SQL Server level, whereas virtual fields are computed row by row in X++.
Computed column can return only string values.
Data entity view method in SalesInvoiceHeaderEntity::computeTotalDiscountAmount
public class SalesInvoiceHeaderEntity extends common
{
/// <summary>
/// SQL to compute the total discount amount for the sales invoice header.
/// </summary>
private static str computeTotalDiscountAmount()
{
DataEntityName dataEntityName = tablestr(SalesInvoiceHeaderEntity);
List fieldList = new List(types::String);
fieldList.addEnd(SysComputedColumn::returnField(dataEntityName, identifierstr(CustInvoiceJour), fieldstr(CustInvoiceJour, EndDisc)));
fieldList.addEnd(SysComputedColumn::returnField(dataEntityName, identifierstr(CustInvoiceJour), fieldstr(CustInvoiceJour, SumLineDisc)));
fieldList.addEnd(SysComputedColumn::returnField(dataEntityName, identifierstr(CustInvoiceJour), fieldstr(CustInvoiceJour, CashDisc)));
return SysComputedColumn::addList(fieldList);
}
}

Like
Report
*This post is locked for comments