Creating KPI rules
Use the Rule builder to create a KPI rule from the user interface. The rule creates KPIs that provide insights into trends across events or business objects.
About this task
To define the rule, you specify the JSON payload for the KPI through the Rule builder by using the following JSON format:
{
"instructions": {
"filter": {
"EQUALS": [{
"SELECT": [
"",
""
]
},
{
"VALUE": [
"",
""
]
}
]
},
"reduce": {
"output": {
"resultAlias": "",
"resultType": ""
},
"expression": {
"fieldPath": "",
"type": "",
"operator": ""
}
},
"window": {
"timeWindows": [
""
],
"fieldPath": ""
},
"dimension": [{
"fieldPath": "",
"type": ""
}]
}
}
The JSON payload includes the following objects and arrays:- Filter
- Filters data with a given expression.
- Reduce
- The mathematical operation that calculates the KPI. In the example, the mathematical operation is a sum. The final value is calculated when the time window elapses.
- Window
- The time window of the calculation. In the example, the calculation runs at minute intervals.
- Dimension
- If a dimension is specified, a separate KPI is calculated for each value of the dimension. In the example, a separate KPI is calculated for EDI documents of type 850 and 856.
Procedure
Results
businessRuleEvent
is sent to record the
KPI.Example
dailyDocumentVolume
. The object model has two types of EDI
documents, 850 and 856. The rule calculates the total document volume for each EDI document
type.{
"instructions": {
"filter": {
"EQUALS": [
{
"SELECT": [
"eventCode",
"String"
]
},
{
"VALUE": [
"objectUpsertEvent",
"String"
]
}
]
},
"reduce": {
"output": {
"resultAlias": "dailyDocumentVolume",
"resultType": "long"
},
"expression": {
"fieldPath": "eventDetails.eventSource.EDI.size",
"type": "LONG",
"operator": "sum"
}
},
"window": {
"timeWindows": [
"day"
],
"fieldPath": "timestampEventOccurred"
},
"dimension": [
{
"fieldPath": "eventDetails.eventSource.EDI.transactionType",
"type": "STRING"
}
]
}
}
What to do next
businessRuleEvents
by using the rule ID. Use the following query as a guide and
replace the rule ID.{
businessRuleEvents(
simpleFilter: {rule: {id: "8bd65191-782e-4360-b82a-d7f31d51bf29"}}
cursorParams: {first: 1}
) {
totalCount
pageInfo {
endCursor
hasNextPage
}
edges {
cursor
object {
eventCode
timestampEventOccurred
timestampEventReceived
eventDetails {
rule {
id
name
}
dimensionValues {
name
value
}
values {
name
value
}
}
}
}
}
}
Verify that KPI is available in the
values
array under
eventDetails
in the query result For example:{
"data": {
"businessRuleEvents": {
"pageInfo": {
"hasNextPage": false
},
"edges": [{
"cursor": "Yjg2MHM4ZDQtZDc3Ny0zZjg4LWFiNzEtYMQwYzU22TUzzjJj",
"object": {
"eventCode": "businessEvent",
"timestampEventOccurred": "2023-01-20T23:20:00Z",
"timestampEventReceived": "2023-01-20T07:54:00",
"eventDetails": {
"rule": {
"id": "8bd65191-782e-4360-b82a-d7f31d51bf29",
"name": "dailyDocumentVolume"
},
"dimensionValues": [{
"name": "day",
"value": "2023-01-20T23"
},
{
"name": "eventDetails.transactionType",
"value": "850"
}
],
"values": [{
"name": "dailyDocumentVolume",
"value": "100"
}]
}
}
}]
}
}
}
You can also add the query definition to a dashboard card to display the KPI.