To create a Default Dimension in Dynamics 365 F&O with X++ from different dimension values you can use a function like this:
private DimensionDefault createDefaultDimension(DimensionValue _val1, DimensionValue _val2)
{
DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
DimensionDefault result;
int i;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
container conAttr = ['NameDimAttr1','NameDimAttr1'];
container conValue = [_val1, _val2];
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();
return result;
}
In this function you need to modify the method signature by passing the financial dimension values.
The following line of code must contain the names of the dimension attributes
container conAttr = ['NameDimAttr1','NameDimAttr1'];
and there must be consistency in the position in the container with the size values of the following line:
container conValue = [_val1, _val2];