Skip to main content
Version: V2 (Ignition 8.1)

system.mes.unitOfMeasure.saveUnitOfMeasureConversion

Description​

Creates or updates a Unit Of Measure Conversions record in the system based on the provided parameters.

When no id is supplied, the record is matched against an existing conversion on from, to and material together. Direction and material scope are part of that identity, so saving Kg -> Pound creates a new conversion rather than overwriting a stored Pound -> Kg, and saving a material-scoped conversion never overwrites the global one for the same pair. The conversion factor is stored exactly as supplied and is never inverted for you.

Permissions​

This method requires the UNIT_OF_MEASURE.WRITE.SAVE permission.

Syntax​

system.mes.unitOfMeasure.saveUnitOfMeasureConversion(**uomcData)

Parameters​

ParameterTypeNullableDescription
fromIdString (ULID)FalseThe unit of measure the conversion is converting from.
toIdString (ULID)FalseThe unit of measure the conversion is converting to.
conversionFactorDoubleFalseThe number used to change the unit of measure from one set to the other.
materialIdString (ULID)TrueThe material associated with the unit of measure conversion.
idString (ULID)TrueThe ULID of the unit of measure conversion (optional, used for updating an existing unit of measure conversion).
notesStringTrueNotes related to the unit of measure conversion.
enabledBooleanTrueIndicates if the unit of measure conversion is active and enabled. Default value is true
spare1StringTrueAdditional field for user-defined context.
spare2StringTrueAdditional field for user-defined context.
spare3StringTrueAdditional field for user-defined context.

Returns​

Returns a JSON representation of the saved unit of measure conversion.

Code Examples​

# Generate the object structure for a new unit of measure conversion object, set the parameters and save it
newUomc = system.mes.unitOfMeasure.newUnitOfMeasureConversion()
newUomc['toId'] = '01JCH3T85P-KVCB8ZR5-0B83A3SX'
newUomc['conversionFactor'] = 0.33
newUomc['fromId'] = '01JCH4NB3J-BTERAZ27-QEQQN4ME'
savedUomc = system.mes.unitOfMeasure.saveUnitOfMeasureConversion(**newUomc)

# Output the JSON representation of the saved unit of measure conversion
print(savedUomc)

# Generate the object structure for another new unit of measure conversion object to update the previous unit of measure conversion
uomcData = system.mes.unitOfMeasure.newUnitOfMeasureConversion()

# Set basic attributes for the updated unit of measure conversion
uomcData['toId'] = '01JCH3T85P-KVCB8ZR5-0B83A3SX'
uomcData['conversionFactor'] = 0.33
uomcData['fromId'] = '01JCH4NB3J-BTERAZ27-QEQQN4ME'
uomcData['notes'] = 'Conversion from L to BT'
# (You can continue setting other properties as needed here)

# Save the unit of measure conversion to update it in the system
updatedUomc = system.mes.unitOfMeasure.saveUnitOfMeasureConversion(**uomcData)

# Output the JSON representation of the updated unit of measure conversion
print(updatedUomc)