CompanionCompanion
Companion for Delivery
Companion for Business
Companion for Integration
Contact us
Log out
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

serializeReferencesToJSON

The serializeReferencesToJSON function is used to serialize the references from an object.

Syntax

c4i:serializeReferencesToJSON(references [,structure] [, lov] [, units] [, values] [, keyMetaAttribute] [, displayReferenceTarget] [, keysOrder])

Parameters

references

XPath to the root objet (.) will serialize all the references, regardless of their type.

Otherwise, you can target the desired references by providing a custom XPath.

You can also filter the references by using the following function : getReferencesByAttributeGroup

structure

  • Indicates how to represent references
  • The authorized values are "BY_SUPER_TYPE" (default), "BY_TYPE" or "FLAT"
    • "BY_SUPER_TYPE" adds two levels of indexation : Super Type (ProductCrossReference, ClassificationCrossReference, ...) and Reference Type ID
    • "BY_TYPE" adds one level of indexation : Reference Type ID
    • "FLAT" puts all references in an array, regardless of the type and super type

lov (optional) :

  • Indicates how to represent LOV values
  • The authorized values are "DISPLAY_LOV_VALUE_LABEL" (default), "DISPLAY_LOV_VALUE_ID" or "DISPLAY_BOTH"

unit (optional)

  • Indicates how to represent units
  • The authorized values are "NO_UNITS" (default), "DISPLAY_UNIT_ID", "DISPLAY_UNIT_LABEL"

value (optional) :

  • Indicates if values and units should be concatenated or separated
  • The authorized values are "CONCAT_VALUE_UNIT" (default) or "ISOLATE_VALUE"

keyMetaAttribute (optional)

  • By default, attributes are indexed using their attribute ID
  • If this parameter is supplied, attributes will be indexed using a meta-attribute value, if it is present

displayReferenceTarget (optional)

  • Indicates whether to display reference target ID or key value
  • The authorized values are "BY_ID" (default) or "BY_KEY"

keysOrder (optional)

  • Indicates the order in with the keys should be used when an object has multiple key values
  • Separate keys using a comma (,). Example : "Key1,Key2"

Return value

A JSON document containing the references and associated meta-data.

Jsdoc

structure parameterReturn type
BY_SUPER_TYPESingleContextReferencesBySuperType
BY_TYPESingleContextReferencesByType
FLATSingleContextReference[]

Each individual reference is of type SingleContextReference, where the metaData field will be of type Values.

Examples

Given the following STEP XML:

<STEP-ProductInformation>
    <AttributeList>
        <Attribute ID="ATT2">
            <Validation BaseType="number">
                <UnitLink UnitID="unece.unit.KTM"/>
            </Validation>
        </Attribute>
    </AttributeList>
    <Products>
      <Product ID="PRD1">
          <ProductCrossReference Type="Accessory" ProductID="PRD2">
              <MetaData>
                  <MultiValue AttributeID="ATT1">
                      <Value ID="VAL_1">Value 1</Value> 
                      <Value ID="VAL_2">Value 2</Value> 
                  </MultiValue>
                  <MultiValue AttributeID="ATT2">
                      <Value UnitID="unece.unit.KTM">16</Value>
                      <Value UnitID="unece.unit.KTM">12</Value>
                  </MultiValue>
              </MetaData>
          </ProductCrossReference>
          <AssetCrossReference Type="PrimaryImage" AssetID="IMG1"/>
      </Product>
    </Products>
</STEP-ProductInformation>

The following YAML configuration will produce the following output :

c4i:serializeReferencesToJSON(.)
{
  "ProductCrossReference": {
    "Accessory": [
      { 
        "target":  "PRD2",
        "metaData": { "ATT1" :  ["Value 1", "Value 2"], "ATT2" : [16.0, 12.0]}
      }              
    ]   
  },
  "AssetCrossReference": {
    "PrimaryImage": [
      { "target":  "IMG1"}   
    ]  
  }
}

The following YAML configuration will produce the following output :

c4i:serializeReferencesToJSON(".", "BY_TYPE")
{
    "Accessory": [
      { 
        "target":  "PRD2",
        "metaData": { "ATT1" :  ["Value 1", "Value 2"], "ATT2" : [16.0, 12.0]}
      }              
    ] ,
    "PrimaryImage": [
      { "target":  "IMG1"}   
    ]
}

The following YAML configuration will produce the following output :

c4i:serializeReferencesToJSON(ProductCrossReference[@Type="Accessory"], "FLAT")
[
  {
    "target":  "PRD2",
    "metaData": { "ATT1" :  ["Value 1", "Value 2"], "ATT2" : [16.0, 12.0]}
  }
]

Please refer to the documentation of multiValuesToJSON for more info on using the parameter values of this function.

Last Updated: 4/13/26, 10:42 AM
Prev
serializeListOfValueValuesToJSON
Next
serializeReferenceToJSON