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 an if loop and cast operation in D365FO

Chaitanya Golla Profile Picture Chaitanya Golla 17,225

Hi,

In this post, we will view the code to use SysComputedColumn with an if loop and cast operation.

Step 1: Created a view DAXCustomerTrans(namely) and added tables CustTable and CustTrans as its datasources. Added fields AccountNum, TransDate, TransType, DueDate, Description, AmountCur, TransRecId, TransTypeName, Voucher and TransactionAmount.

8360.pastedimage1680133992309v1.png

Step 2: Created a method "computeTransAmount" to display the transaction amount to cast from real to integer for Payment transactions.

public static str computeTransAmount()
    {
        TableName   viewName      = tableStr(DAXCustomerTrans); //Entity name
        str         transTypeName = SysComputedColumn::returnField(viewName, identifierStr(CustTrans), identifierStr(TransType));
        str         amountCurStr  = SysComputedColumn::returnField(viewName, identifierStr(CustTrans), identifierStr(AmountCur));

        return SysComputedColumn::if (SysComputedColumn::equalExpression(transTypeName, SysComputedColumn::returnLiteral(LedgerTransType::Payment)),
                                      SysComputedColumn::cast(amountCurStr, 'int'),
                                      amountCurStr);
    }

Step 3:   Assigned view method "computeTransAmount" to the field "TransactionAmount".

pastedimage1680134442288v3.png

Step 4: Build the solution. In the table browser able to see the transaction amount being truncated (column transaction amount) for payment transactions.

Output:

6886.pastedimage1680134309899v2.png

Thanks,

Chaitanya Golla

Comments

*This post is locked for comments