Representing Calculated Fields in XML¶
Calculated fields are defined as field elements with an additional XML attribute, dataSetExpression, that holds the calculation for the field.
field¶
The field element is a child of the fieldList element. The location of the fieldList element for calculated fields depends on the location of the fields used in the calculation:
-
Calculated fields where all the columns in the calculation come from a single table appear twice in the design file:
- Under the
jdbcTableelement for the join tree that contains the table. - Under the
jdbcTableorjdbcQueryelement for that table.
- Under the
-
Calculated fields that use columns from different tables appear only once, under the
jdbcTableelement for the join tree contains both tables. Remember, it is not possible to create calculated fields from columns in different join trees. -
Constant fields appear under
resourcesas anullelement.
Constant fields are calculated fields that do not reference any column names. Constant fields are defined as field elements in a fieldList under the null element. Because constant fields are not dependent on any column values, they may be used in any join tree or data island. They can also be used in other calculated fields and pre-filters.
XML Attributes¶
Attribute |
Type | Description |
|---|---|---|
dataSetExpression |
String | (Required) Expression that calculates a value. This value is either based on other columns or is a constant value. For a description of the syntax for the expression, including how to reference columns, see Domain Expression Language (DomEL). For information on using attributes in calculated fields, see Using Server Attributes in Design Files. |
|
String | (Required) Identifier for the calculated field. The format of the
The |
|
String | The Java type of the value calculated by the expression, for example |
Example¶
The following example shows the XML for a calculated expression that only references one table, the accounts table. Because it references only the columns of accounts, it appears in that table and in the join tree.
<jdbcTable datasourceId="SugarCRMDataSource" id="accounts"
schemaAlias="public" datasourceTableName="accounts">
<fieldList>
...
<field dataSetExpression="concat( billing_address_city, ', ',
billing_address_state )" id="city_and_state" type="java.lang.String"/>
...
</fieldlist>
</jdbcTable>
...
<jdbcTable datasourceId="SugarCRMDataSource" id="JoinTree_1"
schemaAlias="public" datasourceTableName="anything">
<fieldList>
...
<field dataSetExpression="concat( billing_address_city, ', ',
accounts.billing_address_state )" id="accounts.city_and_state"
type="java.lang.String"/>
...
</fieldlist>
</jdbcTable>
null¶
The null element is a container for constant fields. null is a child of the resources element.
Child Elements¶
| Element Name | Description |
|---|---|
<fieldList> |
(Required) A container for the field elements for constant fields. The null element can contain only one fieldlist element. |
fieldList¶
As a child of null, fieldList is a container for one or more field elements that represent constant fields.
Child Elements¶
| Element Name | Description |
|---|---|
<field> |
(Required) A constant field. Constant fields may be used in any join tree or data island. They can also be used in other calculated fields and pre-filters. |
Example¶
The following example shows the XML for two constant calculated fields.
<resources>
<null id="constant_fields_level" datasourceId="FoodmartDataSourceJNDI">
<fieldList>
<field id="CF_Constant" dataSetExpression="1 + 1 + 1" type="java.math.BigInteger" />
<field id="CF_Constant_2" dataSetExpression="12" type="java.math.BigInteger" />
</fieldList>
</null>
...
</resources>