Add a computed column to a view example

In this example we are going to extend the ProjTransPostingView with 2 computed fields. Display value for the Default dimension and the Display value for the LedgerDimension. Btw a Ledger dimension is the Main account + Default dimension.

Firstly we need to create an extension for the view ProjTransPostingView

Add the following fields to the extension:

Next step is create an Extension class for the ProjTransPostingView with for example the name FOXProjTransPostingView_Extension with the following syntax:

We add the following static methods methods, both returning a string value which represent the displayvalue for resp. DefaultDimension and LedgerDimension.

getDisplayValueDefaultDimension:

retuns the displayvalue for the ProjTransPostingView defaultDimension field. DefaultDimension corresponds with the field DimensionAttributeValue from the table DimensionAttributeValueSetItem.

In the methods we declare a string (projTransPostingDS) which represents an expression for the ProjectTransPosting datasource of the  ProjTransPostingView. To do this we declare a DictView object with the tablinum ProjTransPostingView as parameter.

We will look for the most feasible field to join up with the DimensionAttributeValueSetItem table. The DefaultDimension field seems the most suitable, however for the ProjTransPosting View it’s not available as a field, so we need to select the field TransId instead.Via the TransId field we can finally join the DimensionAttributeValueSetItem table.

In SQL management studio we can see the clause we need to incorporate into the X++ strfmt function:

Now we can complete writing the method which looks as follows:

getDisplayValueLedgerDimension:

It returns the displayvalue for the ProjTransPostingView Ledgerdimension field. LedgerDimension corresponds with the RecId from the table DimensionAttributeValueCombination.

The method looks as follows:

Now we gonna back to the ProjTransPostingView extension, to make some additions in the field parameters section.

In the View Method parameter we need add the method we created in the extension class:

FOXProjTransPostingView_Extension::getDisplayValueLedgerDimension for the FOXDisplayValueDefaultDimension field and

FOXProjTransPostingView_Extension::getDisplayValueLedgerDimension for the FOXDisplayValueLedgerDimension field.

For both fields we add for the Extended Data Type parameter the extend data type DimensionValue.

Now our solution is ready for compilation and synchronization. To test the solution we can create a select clause in SQL management Studio: