web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

Community site session details

Community site session details

Session Id :

X++ code using SysComputedColumn to use Null expression in D365FO

Chaitanya Golla Profile Picture Chaitanya Golla 17,225

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.

DateDiffNull1.jpg

On firing the OData call to the entity, received the below output with column DatesDiff showing the difference between the dates (in days).

DateDiffNull2.jpg

Regards,

Chaitanya Golla

Comments

*This post is locked for comments