In Dynamics 365 Finance and Operations, ensuring consistency across ledger dimensions is crucial for accurate financial management. One common scenario involves updating the business unit value in the ledger dimension to reflect changes made in the offset ledger dimension.
Our blog explores a streamlined approach to meet this requirement seamlessly.
** Our provided code, tailored for business unit updates in ledger dimensions, exemplifies a flexible to a other dimensional attributes. Whether it's modifying cost centers, departments, or any other dimension, our framework seamlessly adapts, simply we have to change the respective attribute name.
[ExtensionOf(tablestr(LedgerJournalTrans))]
public class ledgerJournalTrans_Table_Extension
{
public void modifiedField(FieldId _fieldId)
{
next modifiedField( _fieldId;
switch (_fieldId)
{
DimensionAttributeLevelValueAllView dimensionAttributeLevelValueAllViewloc,dimensionAttributeLevelValueAllView;
RecId defaultAccount;
LedgerJournalTrans ledgerJournalTrans;
case fieldNum(LedgerJournalTrans, OffsetLedgerDimension):
select DimensionAttributeLevelValueAllViewloc
where DimensionAttributeLevelValueAllViewloc.ValueCombinationRecId==this.OffsetLedgerDimension
&& DimensionAttributeLevelValueAllViewloc.DimensionAttribute==DimensionAttribute::findByName("BusinessUnit").RecId;
defaultAccount = LedgerDefaultAccountHelper::getDefaultAccountFromLedgerDimension(this.LedgerDimension);
DimensionAttributeValueSetStorage defaultDimensionValues = DimensionAttributeValueSetStorage::find(this.LedgerDimension);
while select dimensionAttributeLevelValueAllView
where dimensionAttributeLevelValueAllView.ValueCombinationRecId==this.LedgerDimension
{
defaultDimensionValues.addItem(DimensionAttributeValue::findByDimensionAttributeAndValue(DimensionAttribute::find(dimensionAttributeLevelValueAllView.DimensionAttribute),
dimensionAttributeLevelValueAllView.DisplayValue, false, true));
}
defaultDimensionValues.addItem(DimensionAttributeValue::findByDimensionAttributeAndValue(DimensionAttribute::findByName("BusinessUnit")
,DimensionAttributeLevelValueAllViewloc.DisplayValue, false, true));
Recid newLedgerDimension = LedgerDimensionFacade::serviceCreateLedgerDimension(defaultAccount, defaultDimensionValues.save());
this.LedgerDimension=newLedgerDimension;
}
}
}
