APPROACH 1
//calling method
DimensionAttributeValueSetStorage valueStorage = this.getDefaultDimension(inventsite);
purchTable.defaultdimension = valueStorage.save();
//Method to create DimensionAttributeValueSetStorage
public DimensionAttributeValueSetStorage getDefaultDimension(InventSite inventSite)
{
DimensionDefault result;
int i;
DimensionAttribute dimensionAttribute, dimensionAttribute1, dimensionAttribute2, dimensionAttribute3;
DimensionAttribute dimensionAttribute4, dimensionAttribute5, dimensionAttribute6;
DimensionAttributeValue dimensionAttributeValue, dimensionAttributeValue1, dimensionAttributeValue2;
DimensionAttributeValue dimensionAttributeValue3, dimensionAttributeValue4, dimensionAttributeValue5;
DefaultDimensionView defaultDimensionView;
container dimAttr, dimValue;
str dimValues;
DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
DimensionAttributeValueDerivedDimensions derivedDim, derivedDim2;
InventParameters inventParameters;
select firstonly SiteDimensionAttribute from inventParameters
join RecId,Name from dimensionAttribute6
where dimensionAttribute6.RecId == inventParameters.SiteDimensionAttribute;
select firstonly DefaultDimension, Name, DisplayValue from defaultDimensionView
where defaultDimensionView.DefaultDimension == inventSite.DefaultDimension
&& defaultDimensionView.Name == dimensionAttribute6.Name;
dimAttr += [defaultDimensionView.Name];
dimValue += [defaultDimensionView.DisplayValue];
select firstonly DimensionKeyColumnName, RecId from dimensionAttribute
where dimensionAttribute.DimensionKeyColumnName == defaultDimensionView.Name
join firstonly DimensionAttribute, DimensionAttributeValue, DerivedDimensionAttributeValue1, DerivedDimensionAttributeValue2 from derivedDim
where derivedDim.DimensionAttribute == dimensionAttribute.RecId
join DisplayValue, RecId from dimensionAttributeValue
where dimensionAttributeValue.DisplayValue == defaultDimensionView.DisplayValue
&& derivedDim.DimensionAttributeValue == dimensionAttributeValue.RecId;
select firstonly DisplayValue, DimensionAttribute from dimensionAttributeValue1
where derivedDim.DerivedDimensionAttributeValue1 == dimensionAttributeValue1.RecId
join firstonly RecId, Name from dimensionAttribute1
where dimensionAttributeValue1.DimensionAttribute == dimensionAttribute1.RecId;
dimAttr += [dimensionAttribute1.Name];
dimValue += [dimensionAttributeValue1.DisplayValue];
select firstonly DimensionKeyColumnName from dimensionAttribute4
where dimensionAttribute4.DimensionKeyColumnName == dimensionAttribute1.Name
join firstonly DimensionAttribute, DimensionAttributeValue, DerivedDimensionAttributeValue1 from derivedDim2
where derivedDim2.DimensionAttribute == dimensionAttribute1.RecId
join firstonly DisplayValue, Recid from dimensionAttributeValue4
where dimensionAttributeValue4.DisplayValue == dimensionAttributeValue1.DisplayValue
&& derivedDim2.DimensionAttributeValue == dimensionAttributeValue4.RecId;
select firstonly DimensionAttribute, RecId, DisplayValue from dimensionAttributeValue5
where derivedDim2.DerivedDimensionAttributeValue1 == dimensionAttributeValue5.RecId
join firstonly RecId, Name from dimensionAttribute5
where dimensionAttributeValue5.DimensionAttribute == dimensionAttribute5.RecId;
dimAttr += [dimensionAttribute5.Name];
dimValue += [dimensionAttributeValue5.DisplayValue];
select firstonly DimensionAttribute, RecId, DisplayValue from dimensionAttributeValue2
where derivedDim.DerivedDimensionAttributeValue2 == dimensionAttributeValue2.RecId
join firstonly Name, RecId from dimensionAttribute2
where dimensionAttributeValue2.DimensionAttribute == dimensionAttribute2.RecId;
dimAttr += [dimensionAttribute2.Name];
dimValue += [dimensionAttributeValue2.DisplayValue];
for (i = 1; i <= conLen(dimAttr); i++)
{
dimensionAttribute3 = DimensionAttribute::findByName(conPeek(dimAttr,i));
if (dimensionAttribute3.RecId == 0)
{
continue;
}
dimValues = conPeek(dimValue,i);
if (dimValues != "")
{
dimensionAttributeValue3 = DimensionAttributeValue::findByDimensionAttributeAndValue
(dimensionAttribute3,dimValues,false,true);
valueSetStorage.addItem(dimensionAttributeValue3);
}
}
return valueSetStorage;
}
APPROACH 2
If Dimension link is activated on site
purchTable.DefaultDimension = InventSite::changeDimension(purchTable.DefaultDimension, InventLocation::find(_avaTmpPurchLine.InventLocationId).InventSiteId);