update default dimensions in ax 2012
class ProjDimUpload
{
}
class ProjDimUpload
{
}
..............................................................
public void importProjDim()
{
RecId recIdDefaultDimension,Dimension3,itemid;
//table
ForecastSales forecastSales,forecastSalesLoc;
CustTable custTable;
DefaultDimensionView defaultDimensionView;
InventTable inventTable;
container financialDimensionFromExcel;
container conDimensionName;
;
while select forecastSales
{
select forupdate forecastSalesLoc where forecastSalesLoc.CustAccountId == forecastSales.CustAccountId
&& forecastSalesLoc.ItemId == forecastSales.ItemId
&& forecastSalesLoc.RecId == forecastSales.RecId;
conDimensionName = this.TIDgetDimensionName();
financialDimensionFromExcel += "";
financialDimensionFromExcel += "";
financialDimensionFromExcel += forecastSalesLoc.CustAccountId;
financialDimensionFromExcel += "";
financialDimensionFromExcel += "";
financialDimensionFromExcel += forecastSalesLoc.ItemId;
financialDimensionFromExcel += "";
financialDimensionFromExcel += "";
custTable = CustTable::find(forecastSalesLoc.CustAccountId);
recIdDefaultDimension = this.TIDcreateDefaultDimension(conDimensionName,financialDimensionFromExcel);
Dimension3 = DimensionDefaultingService::serviceMergeDefaultDimensions(recIdDefaultDimension, custTable.DefaultDimension);
Dimension3 = DimensionDefaultingService::serviceMergeDefaultDimensions(itemid, custTable.DefaultDimension);
forecastSalesLoc.DefaultDimension =Dimension3;
//forecastSalesLoc.DefaultDimension = recIdDefaultDimension;
forecastSalesLoc.update();
}
}
.............................................................................
Public DimensionDefault TIDcreateDefaultDimension(container _attr, container _value, boolean _createIfNotFound = true)
{
DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
DimensionDefault result;
int i;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
//_attr is dimension name in table DimensionAttribute
container conAttr = _attr;
container conValue = _value;
str dimValue;
for (i = 1; i <= conLen(conAttr); i++)
{
dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));
if (dimensionAttribute.RecId == 0)
{
continue;
}
dimValue = conPeek(conValue,i);
if (dimValue != "")
{
// _createIfNotFound is "true". A dimensionAttributeValue record will be created if not found.
dimensionAttributeValue = dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,_createIfNotFound);
// Add the dimensionAttibuteValue to the default dimension
valueSetStorage.addItem(dimensionAttributeValue);
}
}
result = valueSetStorage.save();
return result;
}
..............................
public container TIDgetDimensionName()
{
DimensionAttribute dimAttr;
DimensionAttributeSetItem dimAttrSetItem;
DimensionEnumeration dimensionSetId;
DimensionAttributeValue dimAttributeValue;
container DimensionName;
dimensionSetId = DimensionCache::getDimensionAttributeSetForLedger();
while select dimAttr order by Name
where dimAttr.Type != DimensionAttributeType::MainAccount
join RecId from dimAttrSetItem
where dimAttrSetItem.DimensionAttribute == dimAttr.RecId &&
dimAttrSetItem.DimensionAttributeSet == dimensionSetId
{
dimensionName += dimAttr.Name;
}
return DimensionName;
}
/////////////////////////////////////////
public static void main(Args args)
{
ProjDimUpload projDimUpload = new ProjDimUpload();
projDimUpload.importProjDim();
}