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

Community site session details

Session Id :

X++ code using getDateAdd of SysComputedColumn in D365FO

Chaitanya Golla Profile Picture Chaitanya Golla 17,225

Hi,

In this post will provide the code to show the usage of getDateAdd method of SysComputedColumn in D365FO. In general, it's used to add offset to the given date. For demo purpose, we will view the date prior 30 days to the due date. 

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 computePrior30Days(namely) on entity DAXCustHistoryTransEntity.

Step 2: In this method, used getDateAdd method of SysComputedColumn to calculate 30 days prior date to the due date of data entity DAXCustHistoryTransEntity.

// 
    /// Get the date that is 30 days prior to today.
    /// 
    /// Date 30 days prior to today.
    public static str computePrior30Days()
    {
        TableName   viewName      = tableStr(DAXCustHistoryTransEntity); //Entity name
        str         dueDateStr    = SysComputedColumn::returnField(viewName, identifierStr(DAXCustHistoryTransView), identifierStr(DueDate));

        return SysComputedColumn::getDateAdd('-30',
        dueDateStr);

    }

Step 3: Created a new field Prior30Days on entity DAXCustHistoryTransEntity and assigned the method computePrior30Days to it.

6318.Prior30Days.jpg

On firing the OData call to the entity, received the below output with column Prior30Days showing the date that is 30 days prior to due date.

Prior30DaysOutput.jpg

Thanks,

Chaitanya Golla

Comments

*This post is locked for comments