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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :

X++ code using SysComputedColumn with or2 in D365FO

Chaitanya Golla Profile Picture Chaitanya Golla 17,225

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.

4520.pastedimage1674074189804v1.png

Output:

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

1778.pastedimage1674074249353v2.png

Regards,

Chaitanya Golla

Comments

*This post is locked for comments