Skip to main content

Notifications

Community site session details

Community site session details

Session Id :

X++ code using SysComputedColumn with a Switch case in D365FO

Chaitanya Golla Profile Picture Chaitanya Golla 17,225

Hi,

In this post, we will view the code to use Switch case of SysComputedColumn in D365FO.

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 and TransTypeName.

pastedimage1680111902962v1.png

Step 2: Created a method "computedTransType" to display the transaction type value as 0 for invoice and Payment transactions using Switch method of SysComputedColumn.

	private static str computedTransType()
    {
        TableName   viewName      = tableStr(DAXCustomerTrans); //Entity name
        str         transTypeName = SysComputedColumn::returnField(viewName, identifierStr(CustTrans), identifierStr(TransType));
       
		Map comparisonMap = SysComputedColumn::comparisionExpressionMap();

		// Invoice
		comparisonMap.insert(SysComputedColumn::returnLiteral(8), SysComputedColumn::returnLiteral(0));
		// Payment
		comparisonMap.insert(SysComputedColumn::returnLiteral(15), SysComputedColumn::returnLiteral(0));

		return SysComputedColumn::switch(transTypeName, comparisonMap, transTypeName);
    }

Step 3:   Assigned view method "computedTransType" to the field "TransTypeName".

4276.pastedimage1680111247816v1.png

Step 4: Build the solution. In the table browser able to see the trans type as zero for invoice and payment transactions.

Output:

pastedimage1680111603252v2.png

Thanks,

Chaitanya Golla

Comments

*This post is locked for comments