Sunday, 25 October 2015

Insert/Update /Replace Financial Dimension in Default Dimension [AX 2012]

Hi,

Insert/Update /Replace Financial Dimension in Default Dimension AX 2012.
I was a requirement to Insert/update Financial Dimension in Default Dimension. The job job was pretty big to play with financial dimension in AX 2012.

Here is the Job bellow to change the dimension....

static void UpdateDefaultDimensions(Args _args)
{

CustTable                       csttbl = CustTable::find("C-00001");
Struct                          struct = new Struct();
container                       defDimensionCon;
DimensionDefault                dimDefault;
DimensionAttributeSetItem       dimAttrSetItem;
DimensionAttribute              dimAttribute;
int i; //For looping


while select Name, BackingEntityType from dimAttribute
where dimAttribute.BackingEntityType == tableNum(DimAttributeSmmCampaignTable) ||
dimAttribute.BackingEntityType == tableNum(DimAttributeOMDepartment) ||
dimAttribute.Type              != DimensionAttributeType::DynamicAccount
join dimAttrSetItem
where dimAttrSetItem.DimensionAttribute == dimAttribute.RecId &&
dimAttrSetItem.DimensionAttributeSet == DimensionCache::getDimensionAttributeSetForLedger()
{
if (dimAttribute.BackingEntityType == tableNum(DimAttributeSmmCampaignTable))
{
struct.add(dimAttribute.Name, "00006");
}
else if (dimAttribute.BackingEntityType == tableNum(DimAttributeOMDepartment))
{
struct.add(dimAttribute.Name, ‘DEP-002’);
}
}
defDimensionCon += struct.fields();

for (i = 1; i <= struct.fields(); i++)
{
defDimensionCon += struct.fieldName(i);
defDimensionCon += struct.valueIndex(i);
}
if (struct.fields())
{
dimDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(defDimensionCon);

ttsBegin;
csttbl.selectForUpdate(true);
if (csttbl.DefaultDimension)
{
csttbl.DefaultDimension =                             DimensionDefaultingService::serviceMergeDefaultDimensions(dimDefault,           csttbl.DefaultDimension);
}
else
{
csttbl.DefaultDimension = dimDefault;
}
csttbl.doUpdate();
ttsCommit;
}
info("Dimension Updated....");
}


Happy DAXing :-)

No comments:

Post a Comment

Import General journal from excel in D365 F&O

 Hi Guys, Import General journal from excel in D365 F&O Code:  using System.IO; using OfficeOpenXml; using OfficeOpenXml.ExcelPackage; u...