CompanionCompanion
Companion for Delivery
Companion for Business
Companion for Integration
Contact us
Companion for Delivery
Companion for Business
Companion for Integration
Contact us
  • Companion for Integration

    • Introduction
    • Getting Started
    • Configuration
    • Excel templating
    • How it works
  • YAML Configuration

    • Principles
    • Syntax
    • Validation
  • Custom Functions

    • Summary
    • arrayToJSON
    • bool
    • concatValueAndUnit
    • convertUnit
    • currentContextId
    • exportTime
    • eval
    • firstNonEmpty
    • getContextName
    • getEvents
    • getLastEventTime
    • getReferencesByAttributeGroup
    • getStoredValue
    • getWorkspaceId
    • hash
    • hasStoreKey
    • if
    • integer
    • join
    • mergeInheritedValues
    • multiValuesToJSON
    • number
    • nodeList
    • order
    • resolveUnitLabel
    • serializeAssetPushLocationsToJSON
    • serializeAttributeLinksToJSON
    • serializeContextReferenceToJSON
    • serializeContextReferencesToJSON
    • serializeContextValuesToJSON
    • serializeDataContainerToJSON
    • serializeDataContainersToJSON
    • serializeListOfValueValuesToJSON
    • serializeReferencesToJSON
    • serializeReferenceToJSON
    • serializeValuesToJSON
    • store
    • toXML
    • uppercase
  • Execution

    • Summary
    • Composite
    • From STEP
    • Standalone
    • Performance statistics
  • Configuration

    • ActiveMQ extension
    • Amazon AWS extension (SNS, SQS, Kinesis, S3)
    • ElasticSearch/OpenSearch extension
    • File extension (Excel, CSV, JSON, XML, JSONL, XMLL)
    • Kafka extension
    • Kafka Core extension
    • MongoDB/Cosmos DB extension
    • SQL extension
    • REST extension
    • Google Pub/Sub extension
  • c4i SaaS

    • Introduction
    • Managing jobs
    • Managing executions
    • Managing users
    • Changelog
  • Changelog

    • Core features changelog
    • ActiveMQ extension changelog
    • Amazon AWS extension changelog
    • Composite extension changelog
    • ElasticSearch extension changelog
    • File extension changelog
    • Kafka extension changelog
    • Kafka Core extension changelog
    • MongoDB/Cosmos DB extension changelog
    • SQL extension changelog
    • REST extension changelog
    • Google Pub/Sub extension changelog

convertUnit

The convertUnit function is used to convert an attribute value to a target unit

Syntax

c4i:convertUnit(value, targetUnitId [, errorsAsWarnings])

Parameters

value

The XPath to a XML Value node containing the attribute value and its unit

targetUnitId

The ID of the STEP Unit to convert to

errorsAsWarnings (optional)

If set to true, conversion errors will simply be logged instead of stopping the process

Return value

The converted value.

Thrown exceptions

UnsupportedOperationException

If there is no known conversion between the two units and errorsAsWarnings not set to true

IllegalArgumentException

If there is no unit for the given ID and errorsAsWarnings not set to true

Example

Given the following STEP XML :

<STEP-ProductInformation>
    <UnitList>
        <Unit ID="unece.unit.MMT">
            <Name>mm</Name>
            <UnitConversion BaseUnitID="unece.unit.MTR" Factor=".001" Offset="0"/>
        </Unit>
        <Unit ID="unece.unit.CMT">
            <Name>cm</Name>
            <UnitConversion BaseUnitID="unece.unit.MTR" Factor="0.01" Offset="0"/>
        </Unit>
        <Unit ID="unece.unit.MTR">
            <Name>m</Name>
        </Unit>
    </UnitList>
    <AttributeList>
        <Attribute ID="Length">
            <UnitLink UnitID="unece.unit.MTR"/>
            <UnitLink UnitID="unece.unit.CMT"/>
            <UnitLink UnitID="unece.unit.MMT"/>
        </Attribute>
    </AttributeList>
    <Products>
        <Product UserTypeID="PROD_ARTICLE" ID="123">
            <Name>Test Product</Name>
            <Values>
                <Value AttributeID="Length" UnitID="unece.unit.MMT">12</Value>
            </Values>
        </Product>
    </Products>
</STEP-ProductInformation>

The following YAML configuration will produce the following output :

c4i:convertUnit(Values/Value[@AttributeID="Length"], "unece.unit.MTR"): length
length : 0.012
Last Updated: 7/31/23, 10:35 AM
Prev
concatValueAndUnit
Next
currentContextId