serializeValuesToJSON
The serializeValuesToJSON
function is used to serialize multiple attribute values to a JSON object.
Syntax
c4i:serializeValuesToJSON(xpath [, lov] [, units] [, values] [, attributeGroupFilter] [, keyMetaAttribute])
Parameters
xpath
XPath to the "Values" or "MetaData" XML node will treat all attribute values.
Otherwise, you can filter the desired values by providing a custom xPath.
lov (optional)
- Indicates how to represent LOV values
- The authorized values are "DISPLAY_LOV_VALUE_LABEL" (default), "DISPLAY_LOV_VALUE_ID" or "DISPLAY_BOTH"
units (optional)
- Indicates how to represent units
- The authorized values are "NO_UNITS" (default), "DISPLAY_UNIT_ID", "DISPLAY_UNIT_LABEL"
values (optional)
- Indicates if values and units should be concatenated or separated
- The authorized values are "CONCAT_VALUE_UNIT" (default) or "ISOLATE_VALUE"
attributeGroupFilter (optional)
- This parameter is used to filter the attribute types depending on their attribute group
- Can be a regex
- Attribute group resolution is recursive
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
Return value
A JSON document containing the attribute values.
Example
Given the following STEP XML:
<STEP-ProductInformation>
<UnitList>
<Unit ID="unece.unit.KTM">
<Name>km</Name>
</Unit>
</UnitList>
<AttributeList>
<Attribute ID="ATT1">
<Validation BaseType="text"></Validation>
<MetaData>
<Value AttributeID="ATT_KEY">MyCustomKey</Value>
</MetaData>
</Attribute>
<Attribute ID="ATT2">
<Validation BaseType="number">
<UnitLink UnitID="unece.unit.KTM"/>
</Validation>
</Attribute>
</AttributeList>
<Products>
<Product ID="PRD1">
<Values>
<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>
</Values>
</Product>
</Products>
</STEP-ProductInformation>
The following YAML configuration will produce the following output :
c4i:serializeValuesToJSON(Values, "DISPLAY_LOV_VALUE_LABEL", "NO_UNITS", "CONCAT_VALUE_UNIT")
{"ATT1": ["Value 1", "Value 2"], "ATT2" : [16.0, 12.0]}
The following YAML configuration will produce the following output :
c4i:serializeValuesToJSON(Values, "DISPLAY_LOV_VALUE_LABEL", "NO_UNITS", "CONCAT_VALUE_UNIT", null, "ATT_KEY")
{"MyCustomKey": ["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.
Exporting only changed attributes
When executed in an event-driven OIEP, you can expose only the modified values by providing a custom XPath such as the following :
c4i:serializeValuesToJSON(Values/*[@Changed="true"], "DISPLAY_LOV_VALUE_ID")