serializeContextReferencesToJSON
The serializeReferencesToJSON
function is used to serialize context-dependent references and their context-dependent meta-data
Syntax
c4i:serializeContextReferencesToJSON(references [,structure] [, displayMultiContextValues] [, 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
displayMultiContextValues (optional)
- Indicates if references and values should be indexed by context, then by attribute ID, or the other way around
- The authorized values are "BY_CONTEXT" (default) or "BY_ATTRIBUTE"
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.
Examples
Given the following STEP XML:
<STEP-ProductInformation ExportTime="2020-06-05 10:13:28" ContextID="FR" WorkspaceID="Main">
<AttributeList>
<Attribute ID="Quantity"><Validation BaseType="integer"/></Attribute>
<Attribute ID="Label"><Validation BaseType="text"/></Attribute>
</AttributeList>
<Products>
<Product UserTypeID="PROD_ARTICLE" ID="PRD1">
<ProductCrossReference Type="GlobalComponentReference" ProductID="PRD2">
<MetaData>
<Value AttributeID="Quantity">2</Value>
<Value AttributeID="Label" ContextID="FR">Label 1 FR</Value>
<Value AttributeID="Label" ContextID="EN">Label 1 EN</Value>
</MetaData>
</ProductCrossReference>
<ProductCrossReference ContextID="FR" Type="LocalComponentReference" ProductID="PRD3">
<MetaData>
<Value AttributeID="Quantity">3</Value>
<Value AttributeID="Label" ContextID="FR">Label 2 FR</Value>
<Value AttributeID="Label" ContextID="EN">Label 2 EN</Value>
</MetaData>
</ProductCrossReference>
<ProductCrossReference ContextID="EN" Type="LocalComponentReference" ProductID="PRD4">
<MetaData>
<Value AttributeID="Quantity">4</Value>
<Value AttributeID="Label" ContextID="FR">Label 3 FR</Value>
<Value AttributeID="Label" ContextID="EN">Label 3 EN</Value>
</MetaData>
</ProductCrossReference>
</Product>
</Products>
</STEP-ProductInformation>
The following YAML configuration will produce the following output :
- c4i:serializeContextReferencesToJSON(., "BY_TYPE", "BY_CONTEXT"): contextReferences
{
"globalReferences": {
"GlobalComponentReference": [
{
"target": "PRD2",
"metaData": {
"globalValues": {
"Quantity": 2
},
"contextValues": {
"EN": {
"Label": "Label 1 EN"
},
"FR": {
"Label": "Label 1 FR"
}
}
}
}
]
},
"contextReferences": {
"EN": {
"LocalComponentReference": [
{
"target": "PRD4",
"metaData": {
"globalValues": {
"Quantity": 4
},
"contextValues": {
"EN": {
"Label": "Label 3 EN"
},
"FR": {
"Label": "Label 3 FR"
}
}
}
}
]
},
"FR": {
"LocalComponentReference": [
{
"target": "PRD3",
"metaData": {
"globalValues": {
"Quantity": 3
},
"contextValues": {
"EN": {
"Label": "Label 2 EN"
},
"FR": {
"Label": "Label 2 FR"
}
}
}
}
]
}
}
}
Please refer to the documentation of multiValuesToJSON
for more info on using the parameter values of this function.