RSS

Replace a Financial Dimension in Default Dimensions–Condensed [AX 2012]

24 Nov

In my previous post on Replacing default dimensions, I had provided a job to replace one financial dimension within a default dimension. The job was pretty big and I always thought that Microsoft should have provided some way to do these operations easily. Luckily I found a class that has helped me to condense that job and make it pretty small. I am sharing that job here:

The dimensions for Customer record looks like this before running the job:

image

Here is the job to change the values. We will change the values for Business Unit, Department and Worker all with this simple job:

static void replaceDefaultDimensionsCondense(Args _args)

{

    /*

     * In this job, we will replace the Business Unit Value from BU-001 to BU-002

     * and fill in the values for Department as Dep-001 and Worker as 114

     */

    CustTable                       custTable = CustTable::find(‘CUS-00004′); //Customer Record containing Financial Dimension

    Struct                          struct = new Struct(); //Structure to hold the dimension values to replace

    container                       defDimensionCon; //Container to prepare the required values and dimension attribute combination

    DimensionDefault                dimensionDefault; //Get the replaced dimension recid

    DimensionAttributeSetItem       dimAttrSetItem; //Table to get active dimensions for the legal entity

    DimensionAttribute              dimAttribute; //Table to get the Financial dimensions

    int i; //For looping

 

    //Loop for required dimensions

    while select Name, BackingEntityType from dimAttribute

        where dimAttribute.BackingEntityType == tableNum(DimAttributeOMBusinessUnit) ||

              dimAttribute.BackingEntityType == tableNum(DimAttributeOMDepartment) ||

              dimAttribute.BackingEntityType == tableNum(DimAttributeHcmWorker) &&

              dimAttribute.Type              != DimensionAttributeType::DynamicAccount

              join dimAttrSetItem

                where dimAttrSetItem.DimensionAttribute == dimAttribute.RecId &&

                      dimAttrSetItem.DimensionAttributeSet == DimensionCache::getDimensionAttributeSetForLedger()

    {

        //Add the Dimension name and display value to struct

        if (dimAttribute.BackingEntityType == tableNum(DimAttributeOMBusinessUnit))

        {

            struct.add(dimAttribute.Name, ‘BU-002′);

        }

        else if (dimAttribute.BackingEntityType == tableNum(DimAttributeOMDepartment))

        {

            struct.add(dimAttribute.Name, ‘DEP-002′);

        }

        else if (dimAttribute.BackingEntityType == tableNum(DimAttributeHcmWorker))

        {

            struct.add(dimAttribute.Name, ’114′);

        }

    }

 

    //Prepare the container

    defDimensionCon += struct.fields();

 

    for (i = 1; i <= struct.fields(); i++)

    {

        defDimensionCon += struct.fieldName(i);

        defDimensionCon += struct.valueIndex(i);

    }

 

    //if there are fields in struct

    if (struct.fields())

    {

        //Get the DimensionAttributeValueSet table’s Record ID

        dimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(defDimensionCon);

       

        //Update to Customer

        ttsBegin;

        custTable.selectForUpdate(true);

        if (custTable.DefaultDimension)

        {

            custTable.DefaultDimension = DimensionDefaultingService::serviceMergeDefaultDimensions(dimensionDefault, custTable.DefaultDimension);

        }

        else

        {

            custTable.DefaultDimension = dimensionDefault;

        }

        custTable.doUpdate();

        ttsCommit;

    }

}

 

Dimensions after running the job:

image

Pretty Neat!

The class AxdDimensionUtil is pretty handy to do all these stuff.

About these ads
 
7 Comments

Posted by on November 24, 2012 in AX 2012

 

Tags: , , , ,

7 responses to “Replace a Financial Dimension in Default Dimensions–Condensed [AX 2012]

  1. Anuj

    December 24, 2012 at 2:56 PM

    Hi Sumit,

    I was Looking into the financial dimensions in Ax 2012. Somewhere, i read that we can use the Tables (Like vendTable/CustTable) as Financial Dimensions ? But how can I use a Ax table as
    financial Dimension in Ax 2012? please give one example.

    Anuj

     
    • Sumit Loya

      January 2, 2013 at 11:03 AM

      Hi Anuj,

      While setting up a new financial dimension, there is an option of selecting the source for financial dimension values. In the source, you can select existing list and that will allow you to select predefined tables.

      Sumit

       
  2. AN

    March 7, 2013 at 5:21 PM

    Hi Sumit,

    Thanks for the reply. I am following the above blog for the financial dimension but it gives error, “map is not initialize”. In my case I have around 6 dimension on CustTable form and 4 of them has values. Now I am trying to update the new value in one of 4 fields.

    How to do that ?

     
  3. tinu73

    July 10, 2013 at 2:33 AM

    Hi Sumit,

    Great post, thank you! If i want to replace the value of a custom dimension during PO creation, where is the best place to put this code? For example i have a custom dimension called ‘PO’ and now during PO creation i’m creating a new financial dimension value with the PO-Number (with financialTagCategory() and DimensionFinancialTag) and then would like to replace the defaulted value (is actually empty) with the newly creted value.

    Thanks for you help.

     
    • Sumit Loya

      July 10, 2013 at 12:20 PM

      You can try in PurchTableType class, insert method after data is inserted in PurchTable table, you can go ahead and default the cutom dimension

       
      • Zahir

        April 18, 2014 at 11:57 AM

        Hi Sumit,
        With the use of project i’m creating purchase order. Here in the standard environment, i can able to see the financial dimension values in Line details, but the financial dimension values are not visible in Header.
        I need to update the line details of financial dimension values in header too. How can we achieve this? Any idea? Please share it ASAP.
        Regards,
        Zahir

         

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

 
Follow

Get every new post delivered to your Inbox.

Join 196 other followers

%d bloggers like this: