Search This Blog

Friday, February 17, 2012

Ax2012 Get the Dimension values for the Main Account


Get the Dimension Values for the Main Account

static void krishh_dimensionCombValuesforMainAccount(Args _args)
{
    DimensionAttributeValueCombination  dimAttrValueComb;

    DimensionStorage        dimensionStorage;

    DimensionStorageSegment segment;
    int                     segmentCount, segmentIndex;
    int                     hierarchyCount, hierarchyIndex;
    str                     segmentName, segmentDescription;
    SysDim                  segmentValue;

    DimensionHierarchyLevel  dimensionHierarchyLevel;
    RefRecId recordvalue;
    DimensionAttributeValueCombination dimCombination;
    MainAccount  mainAccount;
    ;

   mainAccount=      
 MainAccount::findByMainAccountId('20901',false,LedgerChartOfAccounts::findByName(curext()).RecId);
    recordvalue=DimensionHierarchy::getAccountStructure(mainAccount.RecId);

    select  recid from dimCombination where  dimCombination.MainAccount==mainAccount.RecId
               && dimCombination.AccountStructure==recordvalue;

    dimAttrValueComb = DimensionAttributeValueCombination::find(dimCombination.RecId);
    setPrefix("Breakup for " + dimAttrValueComb.DisplayValue);

    dimensionStorage = DimensionStorage::findById(dimAttrValueComb.RecId);
    if (dimensionStorage == null)
    {
        throw error("No dimension Specified for the Main Account");
    }
    hierarchyCount = dimensionStorage.hierarchyCount();
    for(hierarchyIndex = 1; hierarchyIndex <= hierarchyCount; hierarchyIndex++)
    {
        setPrefix(strFmt("Hierarchy: %1", DimensionHierarchy::find(dimensionStorage.getHierarchyId(hierarchyIndex)).Name));

        segmentCount = dimensionStorage.segmentCountForHierarchy(hierarchyIndex);
        //Loop through segments and display required values
        for (segmentIndex = 1; segmentIndex <= segmentCount; segmentIndex++)
        {
            segment = dimensionStorage.getSegmentForHierarchy(hierarchyIndex, segmentIndex);
            if (segment.parmDimensionAttributeValueId() != 0)
            {
               // Dimension Name
                segmentName = DimensionAttribute::find(DimensionAttributeValue::find(segment.parmDimensionAttributeValueId()).DimensionAttribute).Name;
         
                 // segment value- Dimension Value
                segmentValue        = segment.parmDisplayValue();

                //Description for dimension)
                segmentDescription  = segment.getName();
                info(strFmt("DimensionName:%1: Value:%2,Description: %3", segmentName, segmentValue, segmentDescription));
            }
        }
    }
}

5 comments:

  1. Hi krishna,

    I want to display the financial dimension value in sales invoice report i.e., Worker( dimension 8). Actually the sales table takes only one default dimension. so how to display the worker dimension from defalut dimension in sales invoice report. Please reply me as soon as possible. Its urgent.

    Thanks,
    Sushmitha

    ReplyDelete
    Replies
    1. Hi Sushmitha,
      I think it is employee dimension not worker Dimension, go to the desgígn and select dataset properties and click on query it will open the selection of dp class,click next it will load with the tables and there will be the section of dimension in that select check box of employee.

      regards,
      krishna.

      Delete
    2. Hi krishna,

      Thanks for quick reply. In sales order header financial dimension tab is there. In that I want to display the last dimension value( It is worker not employee). sales invoice dp class does not contain any dimension values, mat be it contains one default dimension value.

      Thanks,
      Sushmitha

      Delete
    3. Hi Sushmitha,
      You have to create new string field in salesinvoice tmp and get the dimension value and fill in the salesinvoiceDP class insert into that tmp method.
      you can see the following post to get the dimension value and description
      http://krishhdax.blogspot.dk/2013/02/ax2012-get-dimension-description-and.html

      regards,
      krishna.
      krishna.dynamics@gmail.com

      Delete
  2. Hi Krishna,

    I have a requirement where I would like to know from a MainAccount, what is the account structure this main account is linked to and what are the dimensions asscociated with this account structure.

    Do you have any sugesstions on how to achieve this.

    Thanks,
    Ismail.

    ReplyDelete

Thanks for visiting my blog,
I will reply for your comment within 48 hours.

Thanks,
krishna.