MeasurementFieldProperties/Measurement Unit value for a measurement field?
I am trying to get the field value of type measurement. I am able to get the value but unable to get the actual unit of measurement. To use the Dimensions object i need to know the Dimensiond Id, which i think can be possible by using the object of MeasurementFieldProperties.
Can anyone of you please let me know if there is way to get this?
Anu Bhupalam replied
Here is the sample code to get the Unit value for measurement field:
MeasurementFieldProperties meaProps =(MeasurementFieldProperties)getRepositorySchema().getField(TABLE_ID, FIELD_ID);
DimensionId dimensionId = meaProps.getDimensionId();
Dimensions dimensions = new Dimensions();
measurementValue = ((MeasurementValue) mdmValue).getMagnitude();
UnitId unitId = ((MeasurementValue) mdmValue).getUnitId();
UnitProperties unitProps = dimensions.getUnit(dimensionId, unitId);
String unitName = unitProps.getName(Locale.US);
Hope that helps!