Typelist mapping associative arrays
You use a typelist map to partition array objects based on a typelist field (typecode) in the
<array> element. In the ClaimCenter base configuration, the
ClaimMetrics array on Claim contains an example of
a typelist mapping.
<entity xmlns="http://guidewire.com/datamodel"
entity="Claim"
table="claim"
type="retireable">
...
<array arrayentity="ClaimMetric"
desc="Metrics related to this claim."
exportable="false"
ignoreforevents="true"
name="ClaimMetrics">
...
<array-association>
<typelist-map field="ClaimMetricCategory"/>
</array-association>
</array>
...
</entity>
The <typelist-map>
element requires that you set a value for the field attribute. This attribute
specifies the typelist to use to partition the array.
Associative arrays of type <array-associaton> are different from those
created using <link-association> in that they can return more
than a single element. In this case, the code creates an array of
ClaimMetric objects named ClaimMetrics. Each
ClaimMetric object as well as all subtype objects of the
ClaimMetric object contain a property called
ClaimMetricCategory. The array definition code utilizes that fact
and uses the ClaimMetricCategory typelist as a partitioning agent.
The ClaimMetricCategory
typelist contains three typecodes, which are:
ClaimActivityMetricsClaimFinancialMetricsOverallClaimMetrics
Each typecode specifies a category. This category contains multiple
ClaimMetric object subtypes. For example, the
OverallClaimMetrics category contains two
ClaimMetric subtypes:
DaysInitialContactWithInsuredClaimMetricDaysOpenClaimMetric
In another example from the ClaimCenter base configuration,
you see the following defined for ReserveLine.
<entity entity="ReserveLine"
xmlns="http://guidewire.com/datamodel"
...
table="reserveline"
type="retireable">
...
<array arrayentity="TAccount"
arrayfield="ReserveLine"
name="TAccounts"
...
setterScriptability="hidden">
<link-association hasGetter="true" hasSetter="true">
<typelist-map field="TAccountType"/>
</link-association>
</array>
...
</entity>
In this case, the array definition code creates a
<link-association>
array of TAcccount objects
and partitions the array by the TAccountType
typelist typecodes.
Working with array values by using typelist mapping
To retrieve an array value through typelist mapping, use the following syntax:
entity.typecode.propertyEach field has the following meaning:
Field |
Description |
|---|---|
|
The object on which the associative array exists. For example, this object might be the
ReserveLine entity on which the
|
|
The typelist typecode that delimits this array partition, for example,
|
|
A field or property on the array object. For example, the ClaimMetric object
contains the following properties (among others):
|
The following table lists the attributes associated with the
<typelist-map> element.
|
Description |
Default |
|---|---|---|
|
Internal. Do not use. | None |
|
Required. Name of the property to which the array associates. |
None |
|
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 typelist map on the same field. In this case, you need to use the propertyPrefix attribute on at least one of the typelist maps. Providing a value for the attribute avoids the two array associations having the same set of property names. | None |
Example 1
The following example code uses sample data in the Guidewire ClaimCenter base configuration. It
iterates over the members of the ClaimMetrics array that fall into
the OverallClaimMetrics category.
uses gw.api.database.Query
uses gw.transaction.Transaction
var clm = Query.make(Claim).compare(Claim#ClaimNumber, Equals, "235-53-365870").select().AtMostOneRow
for (time in clm.OverallClaimMetrics) {
print(time.Subtype.DisplayName + ": ReachYellowTime = " + time.ReachYellowTime)
}
The output of running this code in the Gosu Scratchpad looks similar to the following:
Days Open: ReachYellowTime = 2018-08-24
Initial Contact with Insured (Days): ReachYellowTime = 2018-02-12Example 2
The following example code also uses the sample data in the Guidewire ClaimCenter base configuration. It first retrieves a specific Claim object and then retrieves a specific ReserveLine object associated with that claim.
uses gw.api.database.Query
uses gw.transaction.Transaction
var clm = gw.api.database.Query.make(Claim).compare(Claim#ClaimNumber, Equals,
"235-53-365870").select().AtMostOneRow
var thisReserveLine = clm.ReserveLines.first()
print(thisReserveLine)
print(thisReserveLine.cashout.CreateTime)
The output of running this code in the Gosu Scratchpad looks similar to the following:
(1) 1st Party Vehicle - Ray Newton; Claim Cost/Auto body
Thu Feb 22 15:35:02 PST 2018Setting array member values
The following example code also uses the sample data in the Guidewire ClaimCenter base
configuration. It uses a query builder expression to retrieve a specific claim
entity. Because the result of the query is read-only, you must first retrieve the
current bundle, then add the claim to the bundle to make its fields writable. The
retrieved claim is the base entity on which the ClaimMetrics array
exists.
The following sample code:
- Retrieves a read-only claim object.
- Adds the claim object to transaction bundle to make it writable.
- Sets specific properties on the ClaimMetric object associated with the claims
that are in the
OverallClaimMetricscategory.
In the definition of the claim object, ClaimCenter associates an array of
ClaimMetric objects—the ClaimMetrics
array—with the Claim object. The metadata definition file also
defines the ClaimMetrics array as being of type
<array-association> using the
ClaimMetricCategory typelist. Thus, you can access array member
properties by first accessing the array member of the proper category.
uses gw.transaction.Transaction
uses gw.api.database.Query
var todaysDate = java.util.Date.CurrentDate
var thisClaim = Query.make(Claim).compare(Claim#ClaimNumber, Equals, "235-53-365871").select().AtMostOneRow
//Query result is read-only, need to get current bundle and add entity to bundle
Transaction.runWithNewBundle(\bundle -> {
if (thisClaim != null) {
thisClaim = bundle.add(thisClaim)
//Print out the current values for the ClaimMetric.ReachYellowTime field on each subtype
for (color in thisClaim.OverallClaimMetrics) {
print("Subtype - " + color.Subtype.DisplayName + ": ReachYellowColor = " + color.ReachYellowTime)
}
print("\nAfter modifying the values...\n")
//Modify the ClaimMetric.ReachYellowColor value and print out the new values
for (color in thisClaim.OverallClaimMetrics) {
color.ReachYellowTime = todaysDate
print("Subtype - " + color.Subtype.DisplayName + ": ReachYellowColor = " + color.ReachYellowTime)
}
}
}, "su")
The output of running this code in the Gosu Scratchpad looks similar to the following:
Subtype - Days Open: ReachYellowColor = 2017-11-08
Subtype - Initial Contact with Insured (Days): ReachYellowColor = 2017-10-30
After modifying the values...
Subtype - Initial Contact with Insured (Days): ReachYellowColor = 2018-03-08
Subtype - Days Open: ReachYellowColor = 2018-03-08
See also
Example: Mapping an entity to entities of a different type
When creating a database entity that refers to multiple entities of a different type, a best practice is to use an associative array with typelist mapping.
About this task
A database entity often requires references to multiple entities of a different type.
One way to implement such references is to use <onetoone> links. In
this case, you must have a separate <foreignkey> element that
corresponds to each such link. These separate <foreignkey> elements
must be on each entity to which the original database entity refers. The separate elements
must also point back to the original database entity. In addition, on each <onetoone>
link, you must specify its linkField attribute to associate the link
with its corresponding <foreignkey> element.
However, this method has a downfall. A <onetoone> link generally
requires a unique relationship to the <foreignkey> element that backs
the link. The relationship must have a unique index on the <foreignkey>
element. Such a relationship and its unique index cannot be present if the
<foreignkey> element is nullable. In this case, nothing enforces the
constraint that the <onetoone> link implies.
A preferable option or best practice would be to use an <array> element and a <link-association> subelement. This configuration produces virtual properties for the original database entity. You can use these virtual properties to access the entity instances to which the original database entity refers.
To illustrate how to do so, consider an example of an automation that checks three kinds of results related to an insurance claim—coverability, handleability, and payability. Take the following steps to map a database entity, Ext_Automation, to three entities of type Ext_AutomationCheckResult—CoverabilityResult, HandleabilityResult, and PayabilityResult:
Procedure
- Create an entity, Ext_Automation.
- Create another entity, Ext_AutomationCheckResult.
- Add to Ext_Automation an array of the Ext_AutomationCheckResult entity.
-
Create one
<foreignkey>element for the Ext_AutomationCheckResult entity that points back to the Ext_Automation entity. - Create a typelist named Ext_AutomationResultType.
- Add three type codes to the Ext_AutomationResultType typelist: CoverabilityResult, HandleabilityResult, PayabilityResult.
-
Add a
<typekey>element to the Ext_AutomationCheckResult entity. -
With this
<typekey>element, refer to the Ext_AutomationResultType typelist. -
Under the array of Ext_AutomationCheckResult in the
Ext_Automation entity definition, declare a
<link-association>subelement. -
Under the
<link-association>subelement, declare a<typelist-map>that refers to your<typekey>field from step 7. - Add an <index> subelement to the Ext_AutomationCheckResult entity.
- To ensure unique index entries, set the unique attribute on the <index> subelement to true.
- Add as index columns the Ext_Automation foreign key and the typekey corresponding to the Ext_AutomationResultType typelist.
Results
Ext_Automation
database entity with which to access the three Ext_AutomationCheckResult
types—CoverabilityResult, HandleabilityResult, and
PayabilityResult.