X++ code using SysComputedColumn to use Null expression in D365FO
Hi,
In this post we will view the code to view the difference between two dates using "Null" expression and getDateDiff of SysComputedColumn in D365FO.
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 computeColumnDateDiffNull(namely) on entity DAXCustHistoryTransEntity.
Step 2: In this method, used getDateDiff method and null expression of SysComputedColumn to calculate difference between dates transDate and dueDate of data entity DAXCustHistoryTransEntity.
public static str computeColumnDateDiffNull()
{
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(dueDateStr, SysComputedColumn::returnLiteral(dateNull())),
SysComputedColumn::equalExpression(transDateStr, SysComputedColumn::returnLiteral(dateMax()))),
SysComputedColumn::nullExpression(),
SysComputedColumn::getDateDiff(
dueDateStr, transDateStr,
SysComputedColumnDatePart::Day));
}
Step 3: Created a new field DateDiffNull on entity DAXCustHistoryTransEntity and assigned the method computeColumnDateDiffNull to it.
On firing the OData call to the entity, received the below output with column DatesDiff showing the difference between the dates (in days).
Regards,
Chaitanya Golla

Like
Report
*This post is locked for comments