In Microsoft Dynamics AX 2012 how to update a financial
dimension field by X++ code.
In Microsoft Dynamics AX 2012 how to update a division,
department, location cost center as financial dimension by X++ code.
Applied
on: Dynamics AX 2012 R3 CU8.
Prerequisite: Basic Dynamics AX 2012 programming knowledge.
Target audience: AX programmers.
Assumption: You are familiar with Dynamics AX 2012.
Prerequisite: Basic Dynamics AX 2012 programming knowledge.
Target audience: AX programmers.
Assumption: You are familiar with Dynamics AX 2012.
There was a requirement from one of the functional
analyst to update the 3rd Financial Dimension only. When functional
analyst loaded products to Dynamics AX this financial dimension was missing for
every product. It was about 90 thousand products. Because of huge number of products,
it was possible for him to do it manually. I wrote a X++ job to update it.
Here is the X++ job.
static void
updateFinancialDimension(Args _args)
{
Struct struct = new Struct();
container financialDimension;
DimensionDefault
dimensionDefault;
InventTable
inventTable;
InventItemGroupItem
inventItemGroupItem;
ttsBegin;
select forUpdate
inventtable
where inventTable.dataAreaId == 'your data area id' && inventTable.ItemId
== 'Test';
struct.add('Division', '048');
financialDimension += struct.fields();
financialDimension += struct.fieldName(1);
financialDimension += struct.valueIndex(1);
dimensionDefault =
AxdDimensionUtil::getDimensionAttributeValueSetId(financialDimension);
if (inventTable.RecId)
{
inventTable.DefaultDimension = DimensionDefault;
inventTable.update();
//info(inventTable.ItemId);
}
ttsCommit;
}
After executing the above job I got below result.
Now question is if you need to do it for all the 4
dimensions how to do?
Here I have another X++ job to do it for all the
financial dimension fields update.
static void
updateAllFinancialDimension(Args _args)
{
Struct struct = new
Struct();
container ledgerDimension;
DimensionDefault
dimensionDefault;
InventTable
inventTable;
InventItemGroupItem
inventItemGroupItem;
ttsBegin;
//while select forUpdate inventtable
//
where inventTable.dataAreaId == 'your data area id' &&
inventTable.ItemId == 'Test'
select forUpdate
inventtable
where inventTable.dataAreaId == 'your data area id' && inventTable.ItemId
== 'Test';
struct.add('BusinessUnit', '001');
struct.add('CostCenter', '002');
struct.add('Division', '033');
struct.add('Location', '0475486');
ledgerDimension += struct.fields();
ledgerDimension += struct.fieldName(1);
ledgerDimension += struct.valueIndex(1);
ledgerDimension += struct.fieldName(2);
ledgerDimension += struct.valueIndex(2);
ledgerDimension += struct.fieldName(3);
ledgerDimension += struct.valueIndex(3);
ledgerDimension += struct.fieldName(4);
ledgerDimension += struct.valueIndex(4);
dimensionDefault =
AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimension);
if (inventTable.RecId)
{
inventTable.DefaultDimension = dimensionDefault;
inventTable.update();
//info(inventTable.ItemId);
}
ttsCommit;
}
Hope this was useful. You may leave your comment below.
This comment has been removed by the author.
ReplyDelete