How to ad value to dimension atribute by code


How to generate value for the atribute of dimension. The following code works fine as long as there is projID as value in Project atribute dimension. How to check if it exists and how to generate it.

 DimensionAttributeValue dimAtrrNrProjValue;
 DimensionAttribute dimAttrEwidPodat, dimAtrrNrProjektu, dimAtrrPoddzialStrOrg, dimAttrTA;

 DimensionAttributeValueSetStorage davss;
 RecId defaultDimension;
 ProjTable projTableLoc;

 davss = DimensionAttributeValueSetStorage::find(ProjTable::find(ProjId).DefaultDimension);

// error if no ProjTable.ProjId as atribute valu 
 dimAtrrNrProj = DimensionAttribute::findByName("NrProj");
 dimAtrrNrProjValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAtrrNrProjektu, ProjTable.ProjId, false, true);

 ProjTable.DefaultDimension =;

If the project ID exists and it’s merely not yet used as a dimension value, your code should work. The last parameter of findByDimensionAttributeAndValue() says that the value should be created if it doesn’t exist. You may want to debug the code to see where it fails (the record should be inserted in findByDimensionAttributeAndEntityInst()).