Using preconditions with cumulative variables
When using a cumulative variable, you can set a precondition to accumulate values only when they meet specific criteria. For example, in a transaction scenario, you might want to accumulate only successful transactions or large-value orders. This topic describes how to use pre-calculation logic (preconditions) for a cumulative variable.
Create a custom cumulative variable
This example shows how to accumulate the number of large-value transactions for a single account. A policy is triggered if the number of these transactions exceeds a certain threshold. A large-value transaction is one where the transaction amount exceeds 10,000. This example assumes an event has already been created with the account ID, order number, and transaction amount fields.
-
Go to Variable Center > Custom Cumulative Variable and configure the cumulative variable:
-
Variable Type: Select Count. This deduplicates entries based on the order number.
-
Time Slice: Select Last 7 Days with a sliding window. This includes the seven days prior to the current time.
-
Primary Object: Select account ID.
-
Cumulative Object: Select order number.
-
For Write Event, select order transaction event. For Variable Name, enter Number of large-value transactions from the same account in the last 7 days.
-
Click Add Variable Pre-calculation Logic to set the precondition. Configure the logic to accumulate values only when the transaction amount > 10,000.
Use the custom cumulative variable
-
Go to Policy Management and create a policy. The policy is triggered if the Number of large-value transactions from the same account in the last 7 days is greater than 5. When triggered, the policy outputs the
highRisktag and the count of large-value transactions.
Set the key for the output variable to lrgAmtTrnx. For the value, select Custom Variable/Number of large-value transactions from the same account in the last 7 days. Then, configure the Policy Score Output and decision result as needed.
Verification
-
Verify your configuration by using the Risk Identification OpenAPI. Refer to the following examples.
-
Sample request parameters
Make several calls, changing the
trnxAmt(transaction amount) andorderIdvalues in each call. The system accumulates only calls where the transaction amount is greater than 10,000.{"eventCode":"de_example","accountId":"a001","trnxAmt":"10001","orderId":"00001"}
-
Sample response
When the number of large-value transactions from the same account exceeds 5, the system triggers the policy. The response includes the output tag and the total count of large-value transactions.
{
"Message": "OK",
"RequestId": "FCE6FAFE-B7F3-5528-8012-6CFD7848E449",
"Data": {
"extend": "{\"lrgAmtTrnx\":6.0}",
"tags": "highRisk"
},
"Code": 200
}
In OpenAPI Explorer, set the service endpoint to China (Hangzhou). For Service, enter saf_de, and in ServiceParameters, paste the request JSON. Then, click Initiate Call to view the result.