Including financial dimensions in a form

It is fairly easy to show and maintain financial dimensions from a record on a form. Here is a quick demo:

Create a new table called DEMO_FinancialDimInForm. Add 2 fields:

AccountNum (Extended data type = AccountNum)

DimensionDefault  (Extended data type = DimensionDefault)

Since this is just for showing off I will leave it at this

Demo_LedgerDim1

Now create a form with the same name based on the template SimpleListDetails. Add the DEMO_FinancialDimInForm table as datasource.

Add the AccountNum field to the grid. Add it to the details tab to make sure we can edit it when creating records. Create a new empty tab DimensionTab. It should end up looking more or less like this:

Demo_LedgerDim2

And now let’s move on to the cool part. Add this variable declaration to ClassDeclaration on the form:

    DimensionDefaultingController   dimensionDefaultingController;

This object does the work in handling the dimensions. And it does it without that much work from our site. In the init method add this after the super() call:

    dimensionDefaultingController = DimensionDefaultingController::constructInTabWithValues(true, true, true, 0, this, DimensionTab, "@SYS138487");
    dimensionDefaultingController.parmAttributeValueSetDataSource(DEMO_FinancialDimInForm_ds, fieldStr(DEMO_FinancialDimInForm, DimensionDefault));
    dimensionDefaultingController.pageActivated();

The first line instantiates the object which takes – among others – the formRun and the empty tab page as parameters.

The second line tells the class what data source and which field on the table it should use when handling the financial dimensions.

The third activates the class. If you have the dimensions on a separate tab page on your form you can call the pageActivated method when that tab page is activated to increase performance.

We are now getting close to the finish line. You need to add one line of code to the write, delete and active method on the data source. They should look like this:

public void delete()
{
    super();
     dimensionDefaultingController.deleted();
 }
public void write()
{
    dimensionDefaultingController.writing();
    super();
}
public int active()
{
    int ret;
    ret = super();
    dimensionDefaultingController.activated();
    return ret;
}

Done. Now open the form and watch the magic:

Demo_LedgerDim3

Advertisements

4 thoughts on “Including financial dimensions in a form

  1. Hi, its a nice post ! Thanks for the post. But my scenerio is bit different, i I need help in setting Financial dimension thru X++ when I am posting a inventjournalTrans. For example we receive a XML file by which we get the FinancialTag values for the default Dimension in our system (say Cost center, Dept and purpose). So, how can I set the Default Dimension value to the inventjournalTrans .DefaultDimension tag.

    Thanks ! Any sample codes are appreciated !!!

    Cheers,
    kumar

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s