My thoughts on Dynamics AX application development.
I have been working as a consultant with Microsoft ERP-technology since 1994.
Currently I work at Optimate ApS.
My main focus is customization and application development.
This blog is merely my place to put stuff that I want to remember.
If anybody can benefit from reading this, that's great :0).
Feel free to use any code snippets posted - but accept that you do this at your own risk!!!

tirsdag den 8. maj 2012

Just needed to save some code I have been working on in my blog.

This code is used for basically deconstructing ledger dimensions and default dimensions to be able to merge / overwrite dimension attribute values in the ledger dimension.

My scenario is that during the processing of a ledger allocation, I have an "original" transaction that is being allocated. My destination transaction (the transaction that allocates the original transaction to a new ledger dimension) will inherit all the ledger dimensions of the original transaction BUT will have some of it's dimension attribute values overwritten, by a default dimension set up on the ledger allocation rule destination.

Basically I deconstruct the ledger dimension of the original transaction and put all the found dimensions into a map.

I the deconstruct the default dimension of the ledger allocation rule destination, and find the matching entries in my map, to replace them.

When my "merged" map is complete, I prepare a list of DimensionAttributeValueContract objects that is fed in to a LEdgerAccountContract object.

This is then used when calling DimensionsServiceProvider::BuildDimensionStorageForLedgerAccount to create a DimensionAttributeValueCombination record that can be attached on my LedgerJournalTrans record in the LedgerDimension field.

/// /// Finds or creates a DimensionAttributeValueCombination record/// /// /// GeneralJournalAccountEntry record/// /// /// LedgerAllocationRuleDestination/// /// /// Recid of DimensionAttributeValueCombination record/// /// /// Used to ensure that the correct main account / dimension combination for allocation ledgerJournalTrans are available/// The combination is constructed using dimensions inherited from the "original" generealAccountJournalEntry record that is being allocated/// and the default dimension of the ledgerallocationruleDestination. The dimensions from the ledgerAllocationRuleDestination overrides the/// dimensions of the original generealAccountJournalEntry if set./// private recId findOrCreateDimAttrValueCombination(LedgerJournalTrans _sourceTrans,LedgerAllocationRuleDestination _ledAllocationRuleDest){// These objects are used for constructing a ledgerdimensionLedgerAccountContract ledAccountContract;DimensionAttributeValueContract dimAttrValueContract;List dimAttrValueObjects;Map commonAttributeMap;MapIterator commonAttributeMapInterator;