method %OnExecute() as %Status
In this method, define a query using any logic you need. Then set the %seriesCount, %seriesNames, and %data properties.
Example
The following shows a simple example with hardcoded values:
Method %OnExecute() As %Status
{
Set ..%seriesCount=3
Set ..%seriesNames(1)="alpha"
Set ..%seriesNames(2)="beta"
Set ..%seriesNames(3)="gamma"
Set ..%data(1,"property1")=123
Set ..%data(1,"property2")=100000
Set ..%data(1,"property3")=1.234
Set ..%data(2,"property1")=456
Set ..%data(2,"property2")=200000
Set ..%data(2,"property3")=2.456
Set ..%data(3,"property1")=789
Set ..%data(3,"property2")=300000
Set ..%data(3,"property3")=3.789
Quit $$$OK
}
Defining Cacheable KPIs
By default, a KPI that uses an MDX query is cached (along with all other MDX queries). This cache may or may not be recent enough for your purposes; that is, you can also cache the KPI specifically as described in this section.
By default, non-MDX KPIs are not cached.
To modify a KPI so that its results are cached, make the following changes to the KPI class:
-
Specify the CACHEABLE class parameter as 1.
-
Implement the %OnComputeKPICacheKey() method.
Method %OnComputeKPICacheKey(Output pCacheKey As %String,
pQueryText As %String = "") As %Status
Where pQueryText is the text of the KPI query and pCacheKey is a unique key to associated with the cached results. Typically this is a hashed version of the query text.
-
Implement the %OnComputeKPITimestamp() method.
Method %OnComputeKPITimestamp(ByRef pTimestamp As %String,
pSourceType As %String,
pQueryText As %String = "") As %Status
Where pSourceType is a string that indicates the query type ("mdx", "sql", or "manual"), pQueryText is the text of the KPI query, and pTimestamp is the timestamp of the KPI.
For a given KPI, if %OnComputeKPITimestamp() returns the same timestamp stored in the KPI cache for the given key, the system uses the cached value. Otherwise, the system reruns the KPI.
By default, %OnComputeKPITimestamp() returns a timestamp that is precise to the minute. This means that the cache is kept for a minute (at most) by default.
To clear the cache for a given KPI, call its %ClearKPICache() method.
Note that specifying the FORCECOMPUTE parameter will prevent KPI caching even if CACHEABLE is set.
Defining Asynchronous KPIs
Except for plug-ins, KPIs are executed synchronously.
To modify a KPI so that it executes asynchronously, make the following changes to the KPI class:
-
Specify the ASYNC class parameter as 1.
-
Also modify the KPI so that its results are cached. See the previous section.
This is required so that the system has a place to store the results.
-
Within %OnCompute(), optionally call %SetPercentComplete() to indicate the state of processing. For details, see Indicating State of Completion.