How to pass Account Structure ranges set in AX Ledger to an external system.
Recently I have got a requirement where I have to populate same set of main account and financial dimension values to an external system using integration off course, which I have set in AX Ledger.
The difficulty in this scenario was, how to get the valid set of main account and financial dimension values from AX.
Because AX gives us 'Segmented Entry Controls' where we just have to use the field as a segmented entry control and valid values will populate according to the Account Structure set in Ledger.
I have created a service class which extends "DimensionValueService"
public class CMCDimensionValueService extends DimensionValueService
{
// Insert list of valid main accounts to 'DimensionValueContract'
private void insertMainAccountValueLocalList(List _dimensionValueList,
DimensionAttribute _dimensionAttribute,
DimensionAttributeValue _dimensionAttributeValue,
DimAttributeMainAccount _common)
{
DimensionValueContract dimensionValueContract;
dimensionValueContract = new DimensionValueContract();
dimensionValueContract.parmDimensionAttribute(_dimensionAttribute.Name);
dimensionValueContract.parmBackingEntityType(_dimensionAttribute.BackingEntityType);
dimensionValueContract.parmValue(_common.Value);
dimensionValueContract.parmDescription(_common.Name);
dimensionValueContract.parmActiveFrom(_dimensionAttributeValue.ActiveFrom);
dimensionValueContract.parmActiveTo(_dimensionAttributeValue.ActiveTo);
dimensionValueContract.parmPersonnelNumber(HcmWorker::find
(_dimensionAttributeValue.Owner).PersonnelNumber);
dimensionValueContract.parmGroupDimension(_dimensionAttributeValue.GroupDimension);
dimensionValueContract.parmIsBlockedForManualEntry(
_dimensionAttributeValue.IsBlockedForManualEntry);
dimensionValueContract.parmIsSuspended(_dimensionAttributeValue.IsSuspended);
_dimensionValueList.addEnd(dimensionValueContract);
}
// Insert list of valid financial dimensions to 'DimensionValueContract'
private void insertDimensionValueLocalList(List _dimensionValueList,
DimensionAttribute _dimensionAttribute,
DimensionAttributeValue _dimensionAttributeValue,
Common _common)
{
DimensionValueContract dimensionValueContract;
dimensionValueContract = new DimensionValueContract();
dimensionValueContract.parmDimensionAttribute(_dimensionAttribute.Name);
dimensionValueContract.parmBackingEntityType(_dimensionAttribute.BackingEntityType);
dimensionValueContract.parmValue(_common.(_dimensionAttribute.ValueAttribute));
dimensionValueContract.parmDescription(_common.(_dimensionAttribute.NameAttribute));
dimensionValueContract.parmActiveFrom(_dimensionAttributeValue.ActiveFrom);
dimensionValueContract.parmActiveTo(_dimensionAttributeValue.ActiveTo);
dimensionValueContract.parmPersonnelNumber(HcmWorker::find
(_dimensionAttributeValue.Owner).PersonnelNumber);
dimensionValueContract.parmGroupDimension(_dimensionAttributeValue.GroupDimension);
dimensionValueContract.parmIsBlockedForManualEntry(
_dimensionAttributeValue.IsBlockedForManualEntry);
dimensionValueContract.parmIsSuspended(_dimensionAttributeValue.IsSuspended);
_dimensionValueList.addEnd(dimensionValueContract);
}
[AifCollectionTypeAttribute('return', Types::Class, classStr(DimensionValueContract))]
public List getValidDimensionValues(DimensionContract _dimensionContract, Name _name)
{
DimensionAttribute dimensionAttribute;
List dimensionValueContractList;
if (!_dimensionContract)
{
throw AifFault::faultList("@SYS323958", #DimensionContractIsNotInitialized);
}
if (!_dimensionContract.parmDimensionName())
{
throw AifFault::faultList("@SYS323957", #DimensionContractIsNotInitialized);
}
changecompany(curext())
{
select firstonly dimensionAttribute where dimensionAttribute.Name ==
_dimensionContract.parmDimensionName();
if(dimensionAttribute)
{
dimensionValueContractList = this.getValidDimensionValueList(dimensionAttribute,
_name, _dimensionContract);
}
else
{
throw AifFault::faultList("@SYS323856", #DimensionAttributeDoesNotExist);
}
}
return dimensionValueContractList;
}
// Get the list of valid dimension Values
private List getValidDimensionValueList(DimensionAttribute _dimensionAttribute, Name _name,
DimensionContract _dimensionContract)
{
List dimensionValueList;
DimensionAttributeValue dimensionAttributeValue;
FinancialTagCategory financialTagCategory;
DimensionAttributeDirCategory dimensionAttributeDirCategory;
int categoryFieldNum;
DimensionHierarchyLevel dimHierarchyLevel;
DimensionConstraintNodeView dimConstraintNodeView;
LedgerStructure ledgerStructure;
DimensionHierarchy dimHierarchy;
Common common;
DictTable dictTable;
LedgerChartOfAccounts ledgerChartOfAccounts;
LedgerChartOfAccounts ledgerCOA;
Ledger ledger;
DimAttributeMainAccount mainAccount;
dimensionValueList = new List(Types::Class);
dictTable = new DictTable(_dimensionAttribute.BackingEntityType);
ledgerChartOfAccounts = LedgerChartOfAccounts::find(Ledger::findByLegalEntity
(CompanyInfo::findDataArea(curExt()).RecId).ChartOfAccounts);
if (!ledgerChartOfAccounts)
{
throw AifFault::fault(strFmt("@CMC521", curExt()), "Chart of Account doesn't exist.");
}
select firstonly RecId from ledger
where Ledger.ChartOfAccounts == ledgerChartOfAccounts.RecId
&& Ledger.PrimaryForLegalEntity == CompanyInfo::current();
if (dictTable && dictTable.fieldObject(_dimensionAttribute.NameAttribute)
&& dictTable.fieldObject(_dimensionAttribute.ValueAttribute))
{
common = dictTable.makeRecord();
// Creates a contract of Custom financial dimension
if (_dimensionAttribute.Type == DimensionAttributeType::CustomList)
{
categoryFieldNum = fieldNum(DimensionFinancialTag, FinancialTagCategory);
while select common
outer join DimensionAttribute, ActiveFrom, ActiveTo, Owner, GroupDimension,
IsBlockedForManualEntry, IsSuspended from dimensionAttributeValue
where dimensionAttributeValue.EntityInstance ==
common.(_dimensionAttribute.KeyAttribute)
&& dimensionAttributeValue.DimensionAttribute == _dimensionAttribute.RecId
exists join financialTagCategory
where financialTagCategory.RecId == common.(categoryFieldNum)
exists join dimensionAttributeDirCategory
where (financialTagCategory.RecId == dimensionAttributeDirCategory.DirCategory)
&& (_dimensionAttribute.RecId ==
dimensionAttributeDirCategory.DimensionAttribute)
join dimConstraintNodeView where
(common.(_dimensionAttribute.ValueAttribute) like
dimConstraintNodeView.WildCardString ||
((dimConstraintNodeView.WildCardString == " ") &&
(((dimConstraintNodeView.RangeFrom == " ") ||
((dimConstraintNodeView.IsFromOpen == 0) && (dimConstraintNodeView.RangeFrom <= common.(_dimensionAttribute.ValueAttribute))) ||
((dimConstraintNodeView.IsFromOpen == 1) && (dimConstraintNodeView.RangeFrom < common.(_dimensionAttribute.ValueAttribute)))) &&
((dimConstraintNodeView.RangeTo == " ") ||
((dimConstraintNodeView.IsToOpen == 0) &&
(common.(_dimensionAttribute.ValueAttribute) <= dimConstraintNodeView.RangeTo)) ||
((dimConstraintNodeView.IsToOpen == 1) && (common.(_dimensionAttribute.ValueAttribute) < dimConstraintNodeView.RangeTo))))))
join dimHierarchyLevel
order by
dimHierarchyLevel.Level,
dimHierarchyLevel.DimensionHierarchy
where dimHierarchyLevel.DimensionHierarchy ==
dimConstraintNodeView.DimensionHierarchy &&
dimHierarchyLevel.Level == dimConstraintNodeView.Level &&
dimHierarchyLevel.DimensionAttribute == _dimensionAttribute.RecId
join dimHierarchy
where dimHierarchy.RecId == dimHierarchyLevel.DimensionHierarchy &&
dimHierarchy.Name == _name &&
dimHierarchy.StructureType == DimensionHierarchyType::AccountStructure &&
dimHierarchy.IsDraft == false &&
dimHierarchy.IsSystemGenerated == false
{
this.insertDimensionValueLocalList(dimensionValueList, _dimensionAttribute,
dimensionAttributeValue, common);
}
}
// Creates a contract of valid main accounts
else if (_dimensionAttribute.Type == DimensionAttributeType::MainAccount)
{
while select mainAccount
where MainAccount.Category == ledgerChartOfAccounts.RecId
join ledgerCOA where
ledgerCOA.RecId == mainAccount.Category
&& ledgerCOA.Name == ledgerChartOfAccounts.Name
join dimConstraintNodeView
where (mainAccount.Value like dimConstraintNodeView.WildCardString ||
((dimConstraintNodeView.WildCardString == " ") &&
(((dimConstraintNodeView.RangeFrom == " ") ||
((dimConstraintNodeView.IsFromOpen == 0) &&
(dimConstraintNodeView.RangeFrom <= mainAccount.Value)) ||
((dimConstraintNodeView.IsFromOpen == 1) &&
(dimConstraintNodeView.RangeFrom < mainAccount.Value))) &&
((dimConstraintNodeView.RangeTo == " ") ||
((dimConstraintNodeView.IsToOpen == 0) &&
(mainAccount.Value <= dimConstraintNodeView.RangeTo)) ||
((dimConstraintNodeView.IsToOpen == 1) &&
(mainAccount.Value < dimConstraintNodeView.RangeTo))))))
join dimHierarchyLevel
where dimHierarchyLevel.DimensionHierarchy ==
dimConstraintNodeView.DimensionHierarchy &&
dimHierarchyLevel.Level == dimConstraintNodeView.Level &&
dimHierarchyLevel.DimensionAttribute == _dimensionAttribute.RecId
join dimHierarchy
where dimHierarchy.RecId == dimHierarchyLevel.DimensionHierarchy &&
dimHierarchy.Name == _name &&
dimHierarchy.StructureType == DimensionHierarchyType::AccountStructure &&
dimHierarchy.IsDraft == false &&
dimHierarchy.IsSystemGenerated == false
{
this.insertMainAccountValueLocalList(dimensionValueList, _dimensionAttribute,
dimensionAttributeValue, mainAccount);
}
}
// Creates a contract of other existing financial dimension
else
{
while select common
outer join DimensionAttribute, ActiveFrom, ActiveTo, Owner, GroupDimension,
IsBlockedForManualEntry, IsSuspended from dimensionAttributeValue
where dimensionAttributeValue.EntityInstance ==
common.(_dimensionAttribute.KeyAttribute)
&& dimensionAttributeValue.DimensionAttribute == _dimensionAttribute.RecId
join dimConstraintNodeView where
(common.(_dimensionAttribute.ValueAttribute) like
dimConstraintNodeView.WildCardString ||
((dimConstraintNodeView.WildCardString == " ") &&
(((dimConstraintNodeView.RangeFrom == " ") ||
((dimConstraintNodeView.IsFromOpen == 0) && (dimConstraintNodeView.RangeFrom <= common.(_dimensionAttribute.ValueAttribute))) ||
((dimConstraintNodeView.IsFromOpen == 1) && (dimConstraintNodeView.RangeFrom < common.(_dimensionAttribute.ValueAttribute)))) &&
((dimConstraintNodeView.RangeTo == " ") ||
((dimConstraintNodeView.IsToOpen == 0) && (common.(_dimensionAttribute.ValueAttribute) <= dimConstraintNodeView.RangeTo)) ||
((dimConstraintNodeView.IsToOpen == 1) && (common.(_dimensionAttribute.ValueAttribute) < dimConstraintNodeView.RangeTo))))))
join dimHierarchyLevel
order by
dimHierarchyLevel.Level,
dimHierarchyLevel.DimensionHierarchy
where dimHierarchyLevel.DimensionHierarchy == dimConstraintNodeView.DimensionHierarchy &&
dimHierarchyLevel.Level == dimConstraintNodeView.Level &&
dimHierarchyLevel.DimensionAttribute == _dimensionAttribute.RecId
join dimHierarchy
where dimHierarchy.RecId == dimHierarchyLevel.DimensionHierarchy &&
dimHierarchy.Name == _name &&
dimHierarchy.StructureType == DimensionHierarchyType::AccountStructure &&
dimHierarchy.IsDraft == false &&
dimHierarchy.IsSystemGenerated == false
{
this.insertDimensionValueLocalList(dimensionValueList, _dimensionAttribute, dimensionAttributeValue, common);
}
}
}
return dimensionValueList;
}
}
getValidDimensionValueList() method of the service class returns a list of all valid dimensions according to the account structure set in Ledger. This method takes dimension attribute, Name of the dimension attribute (Business unit, main account etc.) and dimension contract as parameters. And based on these parameters it returns list of valid dimension values.
This list of dimension you can pass to any external system.
Thanks!
Nishant Srivastava
AX Technical Consultant| Campus Management Corp.
Bangalore, Karnataka
will this code will also provide the combinations of business unit and cost center etc ?
ReplyDelete