Create Dimensions through code in d365fo x++
Create Dimensions d365fo x++
Code:
public DimensionDefault createDefaultDimension(str _region, str _baranch, str _profitCenter, str _solution)
{
DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
DimensionDefault result;
int i;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
//Change the dimension names. Use the dimension name which are open and active in the system
//I have given Region, DSAPHcmJobEntity and Costcentre just for an example
container conAttr = ["@DSALabel:DSA000815", "@DSALabel:DSA000851", "Sector", "Solution"];
//Change the values which you want to set in dimensions. Use values which are open and active in the system
//I have given the arguments of function as values for dimensions.
//Dimension name -> dimension value
//Region -> _region
//_baranch -> _baranch
//Costcentre -> _profitCenter
container conValue = [_region, _baranch, _profitCenter, _solution];
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 != "")
{
dimensionAttributeValue = dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);
valueSetStorage.addItem(dimensionAttributeValue);
}
}
result = valueSetStorage.save();
//It reutrns the value of type DimensionDefault
return result;
}
Comments
Post a Comment