How to update Default Financial Dimension in AX 2012 using X++ code

Yes, you can default dimension through x++ code.

Here’s the code by which you can update existing financial dimension.

static void DefaultFinancialDim(Args _args)
{
DimensionAttributeValue dimAttrBUValue,dimAtrrCCValue,dimAtrrDepValue,dimAttrIGValue,dimAtrrProjValue;
DimensionAttribute dimAttrBU,dimAtrrCC,dimAtrrDep,dimAttrIG,dimAtrrProj;
DimensionAttributeValueSetStorage davss;
RecId defaultDimension;
CustTable custTable;

davss = DimensionAttributeValueSetStorage::find(CustTable::find(“US-021”).DefaultDimension);

dimAttrBU = DimensionAttribute::findByName(‘BusinessUnit’);
dimAtrrCC = DimensionAttribute::findByName(‘CostCenter’);
dimAtrrDep = DimensionAttribute::findByName(‘Department’);
dimAttrIG = DimensionAttribute::findByName(‘ItemGroup’);
dimAtrrProj = DimensionAttribute::findByName(‘Project’);

dimAttrBUValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttrBU, “003”, false, true);
dimAtrrCCValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAtrrCC, “009”, false, true);
dimAtrrDepValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAtrrDep, “024”, false, true);
dimAttrIGValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttrIG, “AudioRM”, false, true);
dimAtrrProjValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAtrrProj, “000006”, false, true);

if(dimAttrBUValue || dimAtrrCCValue ||dimAtrrDepValue || dimAttrIGValue || dimAtrrProjValue)
{
davss.addItem(dimAttrBUValue);
davss.addItem(dimAtrrCCValue);
davss.addItem(dimAtrrDepValue);
davss.addItem(dimAttrIGValue);
davss.addItem(dimAtrrProjValue);
custTable = custTable::find(“US-021”, true);
custTable.DefaultDimension = davss.save();
custTable.update();
}

}

Till then, Happy Daxing……….

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: