Gosu Enhancements
GuidewireTraining.com faculty · Updated
Definition: A Gosu enhancement adds new methods and properties to an existing type, including Guidewire entities and Java classes, without subclassing it or changing its source. Enhancements are the standard way to add reusable business logic to entities in InsuranceSuite.
Writing an enhancement
An enhancement is declared with the enhancement keyword, a name and the type it enhances. Inside it, this refers to the enhanced object.
package acme.pc.enhancements
enhancement PolicyPeriodRiskEnhancement : entity.PolicyPeriod {
// A read-only property
property get HasYoungDriver() : boolean {
return this.PersonalAutoLine?.PolicyDrivers?.hasMatch(\ d -> d.Age < 25) ?: false
}
// A method
function vehicleCount() : int {
return this.PersonalAutoLine?.Vehicles?.length ?: 0
}
}
Any Gosu code (rules, PCF expressions, plugins) can now use period.HasYoungDriver and period.vehicleCount().
What enhancements can and cannot do
| Can | Cannot |
|---|---|
| Add methods and properties to a type | Add fields or store state |
| Enhance entities, Gosu classes and Java classes | Override or replace existing methods |
Use this to read the enhanced object |
Change the type’s constructors |
| Be used anywhere the type is used | Access private members of the type |
Enhancement or entity extension?
- Enhancement: behaviour: calculations, derived values, helper methods.
- Entity extension (.etx): data: new columns that must be stored in the database.
A common pattern is to add a field with an entity extension and the logic around it with an enhancement.
Naming and organisation
Keep enhancements small and named after their purpose (for example PolicyPeriodRiskEnhancement), in a package that follows your project’s conventions. This keeps upgrades and code reviews manageable.
Common mistakes
- Trying to store data in an enhancement. Enhancements cannot add fields; add an entity extension for new persistent data.
- Giving an enhancement method the same name as an existing method and expecting it to override it.
- Putting unrelated logic for many concerns into one huge enhancement file instead of small, focused enhancements.
- Running expensive queries inside a property getter that is called repeatedly from PCF screens.
Troubleshooting
- The new property does not appear on the entity in Guidewire Studio.
- Check that the file is an enhancement (.gsx), that it declares the correct enhanced type, and that it compiles without errors; then let Studio re-index the code.
- A compile error says a method is ambiguous.
- Two enhancements on the same type define a member with the same name. Rename one, or consolidate the logic in a single enhancement.
- A screen becomes slow after adding an enhancement property.
- The property is probably recalculated on every render. Move expensive work out of the getter, or compute it once and pass the result to the screen.
Related resources
Examples are simplified for learning. Check exact APIs and behaviour against the documentation for your InsuranceSuite release.