Merging of ledger and default dimensions while creating a new GL journal using DIXF:
While creating the GL journal in Ax using DIXF, below code can be used.
Scenerio:
The financial dimensions needs to be default if they are not provided in the file.
·
If
no Financial dimension is provided in the file, then the values from respective
masters to default.
·
Even
if one financial dimension provided in the file only that value will be
imported. No values should be picked from Master data.
If the Account Type is Customer, Vendor, Bank and Fixed Asset then,
LedgerJournalTrans.DefaultDimension = default dimensions value of the master record &
LedgerJournalTrans.LedgerDimension = CustId or VendId or BankAccount or FixedAsset value
private LedgerJournalTrans mergeLedgerDimensions(LedgerJournalTrans _ledgerJournalTrans)
{
DimensionMerge dimensionMerge;
dimensionMerge = DimensionMerge::newFromTable(_ledgerJournalTrans, _ledgerJournalTrans.companyInfo().RecId);
switch (_ledgerJournalTrans.AccountType)
{
//Customer
case LedgerJournalACType::Cust:
if (!_ledgerJournalTrans.DefaultDimension)
{
_ledgerJournalTrans.DefaultDimension =
dimensionMerge.merge(CustTable::find(DimensionAttributeValueCombination::getDisplayValue(
_ledgerJournalTrans.LedgerDimension)).DefaultDimension, _ledgerJournalTrans.DefaultDimension);
}
break;
//Vendor
case LedgerJournalACType::Vend:
if (!_ledgerJournalTrans.DefaultDimension)
{
_ledgerJournalTrans.DefaultDimension =
dimensionMerge.merge(VendTable::find(DimensionAttributeValueCombination::getDisplayValue(
_ledgerJournalTrans.LedgerDimension)).DefaultDimension, _ledgerJournalTrans.DefaultDimension);
}
break;
//Bank
case LedgerJournalACType::Bank:
if (!_ledgerJournalTrans.DefaultDimension)
{
_ledgerJournalTrans.DefaultDimension =
dimensionMerge.merge(BankAccountTable::find(DimensionAttributeValueCombination::getDisplayValue(
_ledgerJournalTrans.LedgerDimension)).DefaultDimension, _ledgerJournalTrans.DefaultDimension);
}
break;
//FixedAssets
case LedgerJournalACType::FixedAssets:
if (!_ledgerJournalTrans.DefaultDimension)
{
_ledgerJournalTrans.DefaultDimension =
dimensionMerge.merge(AssetTable::find(DimensionAttributeValueCombination::getDisplayValue(
_ledgerJournalTrans.LedgerDimension)).DefaultDimension, _ledgerJournalTrans.DefaultDimension);
}
break;
//Ledger
case LedgerJournalACType::Ledger:
//If Ledger Dimension has no dimensions other than Main account then the below if condition will return 0, otherwise it will return a RecId value.
if (!DimensionStorage::getDefaultDimensionFromLedgerDimension(_ledgerJournalTrans.LedgerDimension))
{
_ledgerJournalTrans.LedgerDimension =
DimensionDefaultingService::ServiceCreateLedgerDimension(_ledgerJournalTrans.LedgerDimension,
MainAccountLegalEntity::findByMainAccountLegalEntity(
MainAccount::findByLedgerDimension(_ledgerJournalTrans.LedgerDimension).RecId,
CompanyInfo::findDataArea(curext()).RecId).DefaultDimension);
}
break;
default:
break;
}
// For Offset dimensions
switch (_ledgerJournalTrans.OffsetAccountType){
//Customer
case LedgerJournalACType::Cust:
if (!_ledgerJournalTrans.OffsetDefaultDimension)
{
_ledgerJournalTrans.OffsetDefaultDimension =
dimensionMerge.merge(CustTable::find(DimensionAttributeValueCombination::getDisplayValue(
_ledgerJournalTrans.OffsetLedgerDimension)).DefaultDimension, _ledgerJournalTrans.OffsetDefaultDimension);
}
break;
//Vendor
case LedgerJournalACType::Vend:
if (!_ledgerJournalTrans.OffsetDefaultDimension)
{
_ledgerJournalTrans.OffsetDefaultDimension =
dimensionMerge.merge(VendTable::find(DimensionAttributeValueCombination::getDisplayValue(
_ledgerJournalTrans.OffsetLedgerDimension)).DefaultDimension, _ledgerJournalTrans.OffsetDefaultDimension);
}
break;
//Bank
case LedgerJournalACType::Bank:
if (!_ledgerJournalTrans.OffsetDefaultDimension)
{
_ledgerJournalTrans.OffsetDefaultDimension =
dimensionMerge.merge(BankAccountTable::find(DimensionAttributeValueCombination::getDisplayValue(
_ledgerJournalTrans.OffsetLedgerDimension)).DefaultDimension, _ledgerJournalTrans.OffsetDefaultDimension);
}
break;
//FixedAssets
case LedgerJournalACType::FixedAssets:
if (!_ledgerJournalTrans.OffsetDefaultDimension)
{
_ledgerJournalTrans.OffsetDefaultDimension =
dimensionMerge.merge(AssetTable::find(DimensionAttributeValueCombination::getDisplayValue(
_ledgerJournalTrans.OffsetLedgerDimension)).DefaultDimension, _ledgerJournalTrans.OffsetDefaultDimension);
}
break;
//ledger
case LedgerJournalACType::Ledger:
if (!DimensionStorage::getDefaultDimensionFromLedgerDimension(_ledgerJournalTrans.OffsetLedgerDimension))
{
_ledgerJournalTrans.OffsetLedgerDimension =
DimensionDefaultingService::ServiceCreateLedgerDimension(_ledgerJournalTrans.OffsetLedgerDimension,
MainAccountLegalEntity::findByMainAccountLegalEntity(
MainAccount::findByLedgerDimension(_ledgerJournalTrans.OffsetLedgerDimension).RecId,
CompanyInfo::findDataArea(curext()).RecId).DefaultDimension);
}
break;
default:
break;
}
return _ledgerJournalTrans;
}