Hi All!
I have a requirement for which if some segments of a default dimensions are changed on the line level (for the first line only), I have to copy those segments to the offset account of the header.
When I looked at the LedgerDimensionFacade::serviceCreateLedgerDimension
method, it seemed like a possible solution, because,
MainAccount::findByLedgerDimension
) andLedgerDimensionFacade::getDefaultDimensionFromLedgerDimension
) from the original OffsetLedgerDimension,To test my understanding of the methods
LedgerDimensionFacade::serviceCreateLedgerDimension
But instead of returning the value equal to VarA, the method returns some other recid.
If you have any information on what am I doing wrong, could you please share it with me...
With best regards,
Abhinay
Hi All,
Thank you for your replies, but the final solution was a bit more than that.
This is the final solution:
public static container getLedgerDimDefaultDimMerge(recId _ledgerDimesnions, DimensionDefault _defaultDimensionRecId) { DimensionHierarchy hierarchy; DimensionHierarchyLevel hierarchyLevel; DimensionHierarchyId hId; hId = DimensionHierarchy::getAccountStructure(MainAccount::findByMainAccountId(MainAccount::findByLedgerDimension(_ledgerDimesnions).MainAccountId).RecId); DimensionStorage dimensionStorage = DimensionStorage::findById(_ledgerDimesnions); container conLedgerDim, conDefaultDim; container segments = conNull(); // Get segments int segmentCount = dimensionStorage.segmentCountForHierarchy(1); String255 segmentName, MainAccount, segmentValue; for (int segmentIndex = 1; segmentIndex <= segmentCount; segmentIndex ) { // Get segment DimensionStorageSegment segment = dimensionStorage.getSegmentForHierarchy(1, segmentIndex); // Get segment name hierarchyLevel = DimensionHierarchyLevel::findByDimensionHierarchyAndLevel(hId, segmentIndex); segmentName = DimensionAttribute::find(hierarchyLevel.DimensionAttribute).Name; // Add segment value segmentValue = segment.parmDisplayValue(); if (segmentIndex == 1) { MainAccount = segmentValue; } conLedgerDim = segmentName; conLedgerDim = segment.parmDisplayValue(); } for (int i = 1; i <= conLen(conLedgerDim); i = 2) { Name name = conPeek(conLedgerDim, i); DefaultDimensionView defaultDimensionView; select defaultDimensionView where defaultDimensionView.DefaultDimension == _defaultDimensionRecId && defaultDimensionView.Name == conPeek(conLedgerDim, i); conDefaultDim = defaultDimensionView.DisplayValue != strMin() ? defaultDimensionView.DisplayValue : conPeek(conLedgerDim, i 1); } return conDefaultDim; }
and passed the container returned in the above given code to:
static int64 getLedgerDimFromMainAccAndDefaultDim(MainAccountNum _mainAccountNum, container _conValue) { container _conData; int hierarchyCount; int hierarchyIdx; RecId dimAttId_MainAccount; LedgerRecId ledgerRecId; MainAccount mainAccount; RefRecId recordvalue; DimensionAttribute dimensionAttribute; DimensionAttributeValue dimensionAttributeValue; DimensionSetSegmentName DimensionSet; DimensionStorage dimStorage; LedgerAccountContract LedgerAccountContract = new LedgerAccountContract(); DimensionAttributeValueContract ValueContract; List valueContracts = new List(Types::Class); dimensionAttributeValueCombination dimensionAttributeValueCombination; _conData = _conValue; mainAccount = MainAccount::findByMainAccountId(_mainAccountNum); recordvalue = DimensionHierarchy::getAccountStructure(mainAccount.RecId,Ledger::current()); hierarchyCount = DimensionHierarchy::getLevelCount(recordvalue); DimensionSet = DimensionHierarchyLevel::getDimensionHierarchyLevelNames(recordvalue); for(hierarchyIdx = 1; hierarchyIdx<=hierarchyCount; hierarchyIdx ) { if(hierarchyIdx == 1) continue; dimensionAttribute = DimensionAttribute::findByLocalizedName(DimensionSet[hierarchyIdx], false, "en-in"); if(dimensionAttribute) { dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,conPeek(_conData, hierarchyIdx)); if(dimensionAttributeValue) { ValueContract = new DimensionAttributeValueContract(); ValueContract.parmName(dimensionAttribute.Name) ; ValueContract.parmValue(dimensionAttributeValue.CachedDisplayValue); valueContracts.addEnd(ValueContract); } } } LedgerAccountContract.parmMainAccount(_mainAccountNum); LedgerAccountContract.parmValues(valueContracts); dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract); dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save()); ledgerRecId = dimensionAttributeValueCombination.RecId; return ledgerRecId; }
Of-course, I am still testing the code for different scenarios.
With best regards,
Abhinay
Hi,
Yes, this method will return a rec id, if you look into the code it's returning a rec id of DimensionAttributeValueCombination. If you want to store the output on a table then you can store the RecId directly but in case you want to use the dim values further try to play around the DimensionAttributeValueCombination table.
You could apply the below code
LedgerDimensionFacade::serviceCreateLedgerDimension(LedgerDefaultAccountHelper::getDefaultAccountFromLedgerDimension(VarB), VarC);
Hi Abhinay,
Please refer to Sukrut's blog to see if it helps:
community.dynamics.com/.../msdynd365fo-working-with-dimensions-x-code-part-i
Martin Dráb
416
Most Valuable Professional
Abhilash Warrier
305
Saalim Ansari
234