Defaulting Ledger Dimensions [AX 2012]

In my earlier post, I had described a way to default financial dimensions through code. In this post, I will describe about the way we can default Ledger Dimensions (DimensionAttributeValueCombination) through code.
We have seen how we can fetch the values from a dimension combination in my post here. But what if we have to default them using code.
Say you are creating a general journal and want to default the Account and Offset account fields. These fields have been changed to segmented controls and now store RecIds for DimensionAttributeValueCombination table.
The job below will help you in doing that.
Below are the screen shots of dimensions for the two record ids used below:
image
image
static void setLedgerDimensions(Args _args)
{
    LedgerDimensionAccount  ledgerDimension; // Record id for LedgerDimension(DimensionAttributeValueCombination) containing combination of dimensions
    LedgerDimensionAccount  mainAccDimension; // Record id for LedgerDimension(DimensionAttributeValueCombination) containing default account for main account RecId
   
    RefRecId    emplDimAttrRecId = 5637147951// For ex. purpose defaulting it to required DimensionAttributeValueSet RecordId
    RefRecId    dimensionRecId = 5637145941// For ex. purpose defaulting it to required DimensionAttributeValueSet RecordId
    ;
    /*
     * For information on finding the record ids for required dimension combinations
     * Go through the following blog
     */
   
    // Get the default account for main account 110154
    mainAccDimension = DimensionStorage::getDefaultAccountForMainAccountNum("110154");
   
    //Find or create the LedgerDimension record for required combination
    //Param1 – Ledger Dimension record id, in our case Default account for main account
    //Param2 – Default Dimension Record Id for 1st Dimension Combination
    //Param3 – Default Dimension Record Id for 2nd Dimension Combination
    //Param4 – Default Dimension Record Id for 3rd Dimension Combination
    ledgerDimension = DimensionDefaultingService::serviceCreateLedgerDimension(
                                                            mainAccDimension,
                                                            dimensionRecId,
                                                            emplDimAttrRecId);

    info(strFmt("%1: %2", ledgerDimension, DimensionAttributeValueCombination::find(ledgerDimension).DisplayValue));
}
This is the output
image

Friends I am updating the post to illustrate how we can default dimensions in case the account is  not a ledger account.
In the job above, you can use  the method getDynamicAccount instead of getDefaultAccountForMainAccount and get non-ledger account ledger dimensions. Here is a small job that shows the same.
static void getNonLedgerAccounts(Args _args)
{
    LedgerDimensionAccount  ledgerDim;
    ledgerDim = DimensionStorage::getDynamicAccount(‘VEN-00273′, LedgerJournalACType::Vend);
    info(strFmt("%1 -%2", ledgerDim, DimensionAttributeValueCombination::find(ledgerDim).DisplayValue));
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.