cancel
Showing results for 
Search instead for 
Did you mean: 

MeasurementFieldProperties/Measurement Unit value for a measurement field?

Former Member
0 Kudos

Hi Friends,

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?

Thanks,

Raags

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Has anyone knows solution for this issue?

Former Member
0 Kudos

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!

Former Member
0 Kudos

Awsome!! Thanks Anu!! It worked like charm!!

My only concern is - Dimensions class is deprecated - ofcourse it allows us to go forward but do you know non-deprecated class?

anyhow thanks for your solution!!

Thanks

Raags

Former Member
0 Kudos

Yes, Dimensions has been deprecated with new release. Instead of Dimensions you can use the DimensionsManager.

Here is the sample code with DimensionsManager:

DimensionsManager dimensionsManager = getDimensionsManager();

DimensionId dimensionId = meaProps.getDimensionId();

measurementValue = ((MeasurementValue) mdmValue).getMagnitude();

UnitId unitId = ((MeasurementValue) mdmValue).getUnitId();

UnitProperties unitProps = dimensionsManager.getUnit(dimensionId, unitId);

String unitName = unitProps.getSuffix();

String value = measurementValue + unitName;

//Getting Dimensions Manager

public static DimensionsManager getDimensionsManager() {

String sessionTag = null;

GetRepositoryDimensionsCommand cmd =

new GetRepositoryDimensionsCommand(connectionAccessor);

sessionTag = getAuthenticatedUserSession(connectionAccessor);

cmd.setSession(sessionTag);

cmd.execute();

dimensionsManager = cmd.getRepositoryDimensions();

return dimensionsManager;

}

Former Member
0 Kudos

Thanks Anu!!! It helps me!!

- Raags

Answers (0)