Hi,
In this post will provide the code to view the usage of or2 condition of SysComputedColumn in D365FO. This is used to implement 'or' condition of SQL.
Setup: Please refer this post to know the details of views DAXCustHistoryInvoices, DAXCustHistoryPayments and data entity DAXCustHistoryTransEntity.
X code using SysComputedColumn with an if loop in D365FO - Dynamics 365 Finance Community
Step 1: Created a new method computeColumnDateDiff(namely) on entity DAXCustHistoryTransEntity.
Step 2: In the method, used or2 and getDateDiff methods of SysComputedColumn to calculate difference between dates transDate and dueDate of data entity DAXCustHistoryTransEntity.
private static str computeColumnDateDiff()
{
TableName viewName = tableStr(DAXCustHistoryTransEntity); //Entity name
str dueDateStr = SysComputedColumn::returnField(viewName, identifierStr(DAXCustHistoryTransView), identifierStr(DueDate));
str transDateStr = SysComputedColumn::returnField(viewName, identifierStr(DAXCustHistoryTransView), identifierStr(TransDate));
return SysComputedColumn::if(
SysComputedColumn::or2(
SysComputedColumn::equalExpression(transDateStr, SysComputedColumn::returnLiteral(dateNull())),
SysComputedColumn::equalExpression(dueDateStr, SysComputedColumn::returnLiteral(dateMax()))),
SysComputedColumn::nullExpression(),
SysComputedColumn::getDateDiff(
transDateStr,
dueDateStr,
SysComputedColumnDatePart::Day));
}
Step 3: Created a new field DatesDiff on entity DAXCustHistoryTransEntity and assigned the method computeColumnDateDiff to it.
Output:
On firing the OData call to the entity, received the below output with column DatesDiff showing the difference between dates (in days).
Regards,
Chaitanya Golla

Like
Report
*This post is locked for comments