Constant mapping associative arrays

You use a constant map to allow the data model itself to specify key-value pairs. To indicate this mapping type, add the <constant-map> subelement to an <array-association> element or a <link-association> element. Then, enter key-value pairs in the definition file.

For example, the following extension code extends the Account entity type and does the following:
  • It defines an array of AccountLocation objects, with each contact associated with a specific role.
  • It adds this array to the Account entity.
  • It defines individual address types directly as properties on a <constant-map> subelement of the <link-association> and <array-association> elements.
<?xml version="1.0"?>
<extension xmlns="http://guidewire.com/datamodel" entityName="Account">
  <array name="AccLocs" arrayentity="AccountLocation">
    <link-association>
      <constant-map field="AddressType">
        <property name="BillingLoc" nullOk="true" value="billing"/>
      </constant-map>
    </link-association>

    <array-association>
      <constant-map field="AddressType">
        <property name="HomeLocs" value="home"/>
        <property name="BusinessLocs" value="business"/>
        <property name="OtherLocs" value="other"/>
      </constant-map>
    </array-association>
  </array>
</extension>

The structure of the constant-map association allows you to specify multiple properties under a constant. Notice that you specify array-association constants and link-association constants in two separate groups.

See also

Working with array values by using constant mapping

To retrieve a member of the Role array, use the following syntax:

base-entity.defined-property

Each field has the following meanings:

FieldDescription

base-entity

The base object on which the associative array exists. For example, consider the Account entity for the Contacts array.

defined-property

The property that you defined for the constant map array.

The following tables list the attributes and subelements associated with the <constant-map> element.

<constant-map> attributes

Description

Default

customAccessor

Internal. Do not use.

None

field

Required. Name of the property to which the array associates.

None

propertyPrefix

Optional attribute that specifies a prefix for every property that an array association generates. This attribute is useful when you have two or more array associations with overlapping keys. For example, suppose that you have two array associations that both have a constant map on the same field. In this case, you need to use the propertyPrefix attribute on at least one of the constant maps. Providing a value for the attribute avoids the two array associations having the same set of property names.
Note: Constant maps generally do not require a propertyPrefix attribute because the property subelement allows full control over property names.

None

<constant-map> subelements

Description

property

Key-value pair in the map.