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 SysComputedColumn to use and operation in D365FO

Chaitanya Golla Profile Picture Chaitanya Golla 17,225

Hi,

In this post, we will view the code to use "and" operation in 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 computeSelectiveCust(namely) on entity DAXCustHistoryTransEntity.

Step 2: In this method, used "and" condition to display the text as "SelectCustPaym" if the customer is "DE-001" and transaction type is "Payment" else display as "OtherCustPaym".

public static str computeSelectiveCust()
    {
        List            transTypeList   = new List(Types::String);
        List            customerList = new List(Types::String);

		TableName   viewName      = tableStr(DAXCustHistoryTransEntity); //Entity name

        transTypeList.addEnd(
                    SysComputedColumn::equalExpression(
                        SysComputedColumn::comparisonField(viewName, identifierStr(DAXCustHistoryTransView) , fieldStr(DAXCustHistoryTransView, TransType)),
						SysComputedColumn::comparisonLiteral(enum2int(LedgerTransType::Payment)))
        );

        customerList.addEnd(
                    SysComputedColumn::equalExpression(
                        SysComputedColumn::comparisonField(viewName, identifierStr(DAXCustHistoryTransView) , fieldStr(DAXCustHistoryTransView, AccountNum)),
                        SysComputedColumn::comparisonLiteral("DE-001")));

        transTypeList.addEnd(SysComputedColumn::and(customerList));

        return SysComputedColumn::if(SysComputedColumn::and(transTypeList),                    
                        SysComputedColumn::returnLiteral("SelectCustPaym"),
                        SysComputedColumn::returnLiteral("OtherCustPaym"));
    }

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

2860.SelectiveCust.jpg

On firing the OData call to the entity, received the below output with column SelecCustPaymTrans showing the text as "SelectCustPaym" or "OtherCustPaym".

SelectiveCustOutput.jpg

Regards,

Chaitanya Golla

Comments

*This post is locked for comments