-->

Passing Financial Dimension combination values in

2019-07-18 02:10发布

问题:

I need to pass Ledger Dimension value for General Journal (Table:LedgerJournalTable) form to LedgerJournalTransDaily(Table:LedgerJournalTrns) form along with combination values. EX:

In General Journal form I am creating a new journal with the journal name "Alloc"(ledger dimension is like 1003), and in Financial dimension tab I am selecting Cost centre(024), department(001), purpose(training) after that I am clicking on lines, then a new form LedgerJournalTransDaily. In the from grid one filed called Account Num, in that segment field I need ledger dimension value along with selected combination value. like 1003-024-001-Training

Thanks in advance

回答1:

The Offset Account Num is the only ledger dimension on the header table, so I'll assume you want to use that, however you can apply this logic with any dimension combination (assuming the ledger account type is Ledger). To combine the ledger dimension with the ledger dimensions fields from LedgerJournalTable, The process is as follows:

First we'll retrieve the Account Num from the offset ledger dimension. You can do this with a simple base AX method:

accountNum = DimensionStorage::ledgerDimension2AccountNum(journalTable.OffsetLedgerDimension);

Next, the financial dimensions on the LedgerJournalTable.

Background info: these dimensions are stored in the field DefaultDimension, which references the table DimensionAttributeValueSet. This table in itself may not seem useful, but it is a cross-reference. Join the DimensionAttributeValueSetItem table where its DimensionAttributeValueSet field equals DimensionAttributeValueSet.RecId. You will see the dimension attributes and their display values that have been selected:

LedgerJournalTable journalTable;
DimensionAttributeValueSet attributeValueSet;
DimensionAttributeValueSetItem attributeValueSetItem;

while select DisplayValue from attributeValueSetItem 
    exists join attributeValueSet
    where attributeValueSet.RecId == attributeValueSetItem.DimensionAttributeValueSet
        exists join journalTable
        where journalTable.DefaultDimension == attributeValueSet.RecId
        && journalTable.RecId               == 52565497166
{
    info(attributeValueSetItem.DisplayValue);
}

Now we have the DimensionAttributeValueSetItem records, we also now have the DimensionAttributeValue and the top tier dimension information stored in DimensionAttribute. We need all these tables! Pretty intense right? You can create a hefty while loop to go through each individual dimension, add it to a container, and combine it with the Account Num retrieved earlier. The container has to be built very specifically to work with the base ax dimension utility methods (or at least the ones I am aware of).

Below is a simple job that effectively does what I have described. I've hand-picked a journal for convenience.

LedgerJournalTable                  journalTable = LedgerJournalTable::findByRecId(52565497166);
DimensionAttribute                  dimensionAttribute;
DimensionAttributeValue             dimensionAttributeValue;
DimensionAttributeValueSet          attributeValueSet;
DimensionAttributeValueSetItem      attributeValueSetItem;
DimensionAttributeValueCombination  davc;
AccountNum                          accountNum;
container                           newLedgerDimension;
int                                 numOfDims;
int                                 i;
str                                 displayValue;
DimensionDynamicAccount             dynamicDimension;

// Get Account Num.
accountNum = DimensionStorage::ledgerDimension2AccountNum(journalTable.OffsetLedgerDimension);
info(AccountNum);

// Add account to container.
newLedgerDimension = [accountNum];

// Add dimensions to the container.
while select attributeValueSetItem
    join RecId from attributeValueSet
    where attributeValueSet.RecId       == attributeValueSetItem.DimensionAttributeValueSet 
    &&    journalTable.DefaultDimension == attributeValueSet.RecId
        join RecId, DimensionAttribute from dimensionAttributeValue
        where dimensionAttributeValue.RecId == attributeValueSetItem.DimensionAttributeValue
            join RecId, Name from dimensionAttribute
            where dimensionAttribute.RecId == dimensionAttributeValue.DimensionAttribute
{
    // Add the dimension name and dimension value
    newLedgerDimension += [dimensionAttribute.Name, attributeValueSetItem.DisplayValue];

    // Keep track of the number of dimensions.
    ++numOfDims;
}

// Combine the account and dimensions into one value.
for (i=1; i<=(numOfDims+1)*2; i+=2)
{
    displayValue += conPeek(newLedgerDimension, i) + '-';
}

// The display value of the combination must be in the first index of the container.
newLedgerDimension = conIns(newLedgerDimension, 1, displayValue);

// The number of dimensions must be in the third index of the container.
newLedgerDimension = conIns(newLedgerDimension, 3, int2str(numOfDims));

info(displayValue);

// Lastly, create the dimension.
dynamicDimension = AxdDimensionUtil::getLedgerAccountId(newLedgerDimension);

info(int642str(dynamicDimension));

If all works out, you have successfully created a combination! You can varify by finding the dimension you just created in DimensionAttributeValueCombination. This combination can now be the RecId in LedgerJournalTrans.LedgerDimension

It should be noted that the dimension utility will only apply dimensions that are applicable based on your configured account structure. This is configured in General Ledger module > Setup > Chart of accounts > Configure account structures.