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.
On firing the OData call to the entity, received the below output with column SelecCustPaymTrans showing the text as "SelectCustPaym" or "OtherCustPaym".
Regards,
Chaitanya Golla

Like
Report
*This post is locked for comments