I have a document model with a field containing an enumeration value and a field of type string. How can a computation assign the unlocalized enumeration value to that string field?
For example in this document model:
<?xml version="1.0" encoding="UTF-8"?>
<model xmlns="http://www.mgm-tp.com/a12/picus/model/v2">
<metadata>
<name>NewDataModel</name>
<languages>en</languages>
<comment/>
<savedAt>2018-09-28T14:45:31.935+02:00</savedAt>
<schemaVersion>22.1.0</schemaVersion>
</metadata>
<group max="1" id="G2" name="NewGroup_1">
<field id="F3" name="NewField_1">
<enumeration>
<value code="FOO">
<text lang="en">foo</text>
</value>
</enumeration>
</field>
<field id="F4" name="NewField_2">
<string/>
</field>
</group>
</model>
I want to create a computation so that NewField_2 is set to the code of the enumeration value of NewField_1. How can I do that?
Hi Andreas,
it is only possible to use enumerations without display values (or the display values are equal to the internal value) for such a computation.
<value> = “internal value”
<text>= “display value”
Currently you’ll get the following error message: It is not allowed to compare enumerations with display values to strings or to enumerations without display values. [MVK_INVALID_COMPARE_ENUM_TO_STRING]
For your example this would mean using either no text or align it:
<?xml version="1.0" encoding="UTF-8"?>
<model xmlns="http://www.mgm-tp.com/a12/picus/model/v2">
<metadata>
<name>DomainEnumTest</name>
<languages>en</languages>
<annotation name="roles">admin</annotation>
<comment/>
<savedAt>2018-10-02T10:38:17.022+02:00</savedAt>
<schemaVersion>22.1.0</schemaVersion>
</metadata>
<group max="1" id="G2" name="NewGroup_1">
<field id="F3" name="NewField_1">
<enumeration>
<value code="foo">
<text lang="en">foo</text>
</value>
</enumeration>
</field>
<field id="F4" name="NewField_2">
<string/>
</field>
<computation id="C5" name="Computation_1">
<fieldIdRef>F4</fieldIdRef>
<errorCode/>
<errorCondition>FieldFilled(NewField_2) and ( ( FieldFilled(NewField_1) and [NewField_2] != [NewField_1] ) )</errorCondition>
<errorMessage>
<text lang="en">error text for computation of Computation_1</text>
</errorMessage>
<severity>error</severity>
</computation>
</group>
</model>
As you can see in the code, for a computation there is always a rule based computation generated where the calculated filed is defined as error field. This is described like all our rules in the negative formulation and in a canonical form containing:
- Intro Condition → calculated field is filled, this rule is always created “behind the curtain”
- Precondition
- Calculation condition → as comparison with != to the calculated field
the parts are liked via ‘AND’ - if you have more than one pair of pre- and calculation condition those are liked with ‘OR’.
This results in the fact that any computation is in the background a comparison (like [NewField_2] != [NewField_1]) and by this the limitations or better to say the “Prohibited comparisons” described in chapter 5.7.1 of the [A12 Validation Language]<INTERNAL_LINK> have to be considered.
The Data Modeler “hides” the negative formulation of Rule-based computations and the computation looks just like in the screenshot.
Just to add to this:
Even when using above described approach you can still localize the enumeration field. For this, you need to add your own localization service in the FormEngineOptions.
This service must be able to deliver the localized texts for the field either when queried with the key for the Document Model field and/or the key for the Form Model control.