Skip to main content

Set key figures in rules

Contacts, portfolios and securities may have additional time series data stored as key figures. These attributes can be retrieved, set or removed by rules using a handy utility called KeyFigureUtils.

Import

The KeyFigureUtils and relevant domain objects needs to be imported into the rule table:

import fi.fasolutions.mod.portfoliomanagement.util.KeyFigureUtils;
import fi.fasolutions.mod.portfoliomanagement.domain.*;
import java.text.SimpleDateFormat;

Usage

Get a key figure value

Example of getting the latest key figure value for key figure <key figure code> for a security $s. If you wish to retrieve a historical key figure value, use the desired date instead of new Date().

KeyFigureUtils.getKeyFigureValue($s, "<key figure code>", new Date(), services);

Set key figure

Example of setting a value of 3 on 1.1.2021 for an integer key figure with the code CO2. The type should correspond to the configuration of the key figure in Preference → Content and translations → Key figures and can be Integer, Double, Boolean or String.

KeyFigureUtils.addKeyFigure($s, "CO2", new SimpleDateFormat("yyyy-MM-dd").parse("2021-01-01"), 3, services);

The same syntax can also be used to replace an existing value. If the security already had a value for the CO2 key figure on 1.1.2021, the method above would update the value to 3.

Remove key figure

Example of removing a key figure CO2 value for 1.1.2021 from a security.

KeyFigureUtils.removeKeyFigure($s, "CO2", new SimpleDateFormat("yyyy-MM-dd").parse("2021-01-01"));