RD 3 - Use Dynamic Variables
Dynamic Variables
Dynamic variables are values used within the Rules Framework that can be updated via configuration or at runtime.
For a more indepth look at dynamic expressions, see the documentation here: Dynamic Expressions
Objective
In the previous step we added a decision based on the value of the payment. Now we want to allow the threshold value to be configurable at runtime, and we will use Dynamic Variables to achieve this.
DSL Set Up
|
To see a completed example of this step, open the |
Creating Dynamic Variables
To start, let’s create a library for the dynamic variables. Right-click on the model, then select
Give the library a name, then add a new entry for our variable. A variable’s type can either be number, string, boolean or a list of the those. We want to make the threshold for what constitutes a high-value payment a configurable value, so create a variable named amountThreshold, give it type number and a default value of 1000.
Testing
Next step: RD 4 - Add Data Table
For each Dynamic variable library created we will need to add it as a bean such as the example below. This configuration class can also be found in the dynamic-variable-solution solution.
package rulestutorialsolution.app.controller;
import com.iconsolutions.kfextensions.runtime.DynamicVariableLibrary;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import rulestutorialmodel.PaymentVariableLibrary;
@Configuration
public class DynamicVariablesConfiguration {
@Bean
public DynamicVariableLibrary dynamicVariableLibrary(){
return PaymentVariableLibrary.INSTANCE;
}
}
Dynamic variables can be overwritten in a few ways. For this example we will cover overwriting the variables via Hocon configuration and using a custom endpoint.
Updating via Configuration
Within ipf-impl.conf add the following configuration
ipf.studio = {
models = [{
name = "rulestutorialmodel"
configurable-values-global ={
amountThreshold = 5000
}
entities =[]
}
]
}
The name must be the name of the model, and the fields should match the variable names.
This will overwrite the variable on a global scope
The application should be ready to run now after another build via:
mvn clean install
Start up the application and try sending the these payments to see the threshold has been changed from 1000 to 5000
curl -d '{"requestId":"HoconLowValueRequest","pacs008":{"grpHdr": {"msgId": "ExampleMessageId", "creDtTm": "2025-10-27T17:27:29.886889529Z", "nbOfTxs": "1", "intrBkSttlmDt": "2025-10-27", "sttlmInf": {"sttlmMtd": "CLRG", "clrSys": {"prtry": "EBA"}}}, "cdtTrfTxInf": [{"pmtId": {"endToEndId": "VIVNxmihFItoyyjAPLTqnwqOpoaWUgFHcFr", "txId": "TugAtCCIQtcUYcFfGVGAHFNfdUjeCokipAn"}, "intrBkSttlmAmt": {"value": 4000, "ccy": "EUR"}, "accptncDtTm": "2025-10-27T17:27:29.878336788Z", "chrgBr": "SLEV", "dbtr": {"nm": "James Allen", "pstlAdr": {"adrLine": ["213 South Street"]}, "id": {"orgId": {"anyBIC": "PRXYITMM"}}}, "dbtrAcct": {"id": {"iban": "GB38UVCRXEHFCFLMQNBTWFSWXISKIW"}, "ccy": "EUR", "nm": "Chloe Williams"}, "dbtrAgt": {"finInstnId": {"bicfi": "ICONGBA1", "clrSysMmbId": {"mmbId": "191919"}, "pstlAdr": {"adrLine": ["897 North Street"]}}}, "cdtrAgt": {"finInstnId": {"bicfi": "ICONGBA0", "clrSysMmbId": {"mmbId": "400302"}, "nm": "Chloe Hughes", "pstlAdr": {"adrLine": ["465 Main Street"]}}, "brnchId": {"id": "iWULDmNwqrZLcrNNmxlELmWDrQGgGdeOavf"}}, "cdtr": {"nm": "Sophia Phillips", "pstlAdr": {"adrLine": ["293 Kingsway"]}, "id": {"orgId": {"lei": "12345678901234567888", "anyBIC": "KJFISESS"}}}, "cdtrAcct": {"id": {"iban": "CZ6508000000192000145399"}}}]}}' -H 'Content-Type: application/json' http://localhost:8080/submit
curl -d '{"requestId":"HoconHighValueRequest","pacs008":{"grpHdr": {"msgId": "ExampleMessageId", "creDtTm": "2025-10-27T17:27:29.886889529Z", "nbOfTxs": "1", "intrBkSttlmDt": "2025-10-27", "sttlmInf": {"sttlmMtd": "CLRG", "clrSys": {"prtry": "EBA"}}}, "cdtTrfTxInf": [{"pmtId": {"endToEndId": "VIVNxmihFItoyyjAPLTqnwqOpoaWUgFHcFr", "txId": "TugAtCCIQtcUYcFfGVGAHFNfdUjeCokipAn"}, "intrBkSttlmAmt": {"value": 6000, "ccy": "EUR"}, "accptncDtTm": "2025-10-27T17:27:29.878336788Z", "chrgBr": "SLEV", "dbtr": {"nm": "James Allen", "pstlAdr": {"adrLine": ["213 South Street"]}, "id": {"orgId": {"anyBIC": "PRXYITMM"}}}, "dbtrAcct": {"id": {"iban": "GB38UVCRXEHFCFLMQNBTWFSWXISKIW"}, "ccy": "EUR", "nm": "Chloe Williams"}, "dbtrAgt": {"finInstnId": {"bicfi": "ICONGBA1", "clrSysMmbId": {"mmbId": "191919"}, "pstlAdr": {"adrLine": ["897 North Street"]}}}, "cdtrAgt": {"finInstnId": {"bicfi": "ICONGBA0", "clrSysMmbId": {"mmbId": "400302"}, "nm": "Chloe Hughes", "pstlAdr": {"adrLine": ["465 Main Street"]}}, "brnchId": {"id": "iWULDmNwqrZLcrNNmxlELmWDrQGgGdeOavf"}}, "cdtr": {"nm": "Sophia Phillips", "pstlAdr": {"adrLine": ["293 Kingsway"]}, "id": {"orgId": {"lei": "12345678901234567888", "anyBIC": "KJFISESS"}}}, "cdtrAcct": {"id": {"iban": "CZ6508000000192000145399"}}}]}}' -H 'Content-Type: application/json' http://localhost:8080/submit
Updating via Custom Endpoint
Another possible approach to updating dynamic variables is using the DynamicExpressionRegistry API. If you look within the rules-tutorial-utils module you will find some extra classes that define a custom endpoint /dynamic-variables that can update the dynamic variables at runtime.
Run the application again and send this message to update the threshold to 10,000 this time.
|
The key for the variable is of the form |
curl -d '{"key":"rulestutorialmodel_amountThreshold","value":10000}' -H 'Content-Type: application/json' http://localhost:8080/dynamic-variable
Now to see the variable has been updated, we can send in new requests with different values.
curl -d '{"requestId":"RuntimeLowValueRequest","pacs008":{"grpHdr": {"msgId": "ExampleMessageId", "creDtTm": "2025-10-27T17:27:29.886889529Z", "nbOfTxs": "1", "intrBkSttlmDt": "2025-10-27", "sttlmInf": {"sttlmMtd": "CLRG", "clrSys": {"prtry": "EBA"}}}, "cdtTrfTxInf": [{"pmtId": {"endToEndId": "VIVNxmihFItoyyjAPLTqnwqOpoaWUgFHcFr", "txId": "TugAtCCIQtcUYcFfGVGAHFNfdUjeCokipAn"}, "intrBkSttlmAmt": {"value": 6000, "ccy": "EUR"}, "accptncDtTm": "2025-10-27T17:27:29.878336788Z", "chrgBr": "SLEV", "dbtr": {"nm": "James Allen", "pstlAdr": {"adrLine": ["213 South Street"]}, "id": {"orgId": {"anyBIC": "PRXYITMM"}}}, "dbtrAcct": {"id": {"iban": "GB38UVCRXEHFCFLMQNBTWFSWXISKIW"}, "ccy": "EUR", "nm": "Chloe Williams"}, "dbtrAgt": {"finInstnId": {"bicfi": "ICONGBA1", "clrSysMmbId": {"mmbId": "191919"}, "pstlAdr": {"adrLine": ["897 North Street"]}}}, "cdtrAgt": {"finInstnId": {"bicfi": "ICONGBA0", "clrSysMmbId": {"mmbId": "400302"}, "nm": "Chloe Hughes", "pstlAdr": {"adrLine": ["465 Main Street"]}}, "brnchId": {"id": "iWULDmNwqrZLcrNNmxlELmWDrQGgGdeOavf"}}, "cdtr": {"nm": "Sophia Phillips", "pstlAdr": {"adrLine": ["293 Kingsway"]}, "id": {"orgId": {"lei": "12345678901234567888", "anyBIC": "KJFISESS"}}}, "cdtrAcct": {"id": {"iban": "CZ6508000000192000145399"}}}]}}' -H 'Content-Type: application/json' http://localhost:8080/submit
curl -d '{"requestId":"RuntimeHighValueRequest","pacs008":{"grpHdr": {"msgId": "ExampleMessageId", "creDtTm": "2025-10-27T17:27:29.886889529Z", "nbOfTxs": "1", "intrBkSttlmDt": "2025-10-27", "sttlmInf": {"sttlmMtd": "CLRG", "clrSys": {"prtry": "EBA"}}}, "cdtTrfTxInf": [{"pmtId": {"endToEndId": "VIVNxmihFItoyyjAPLTqnwqOpoaWUgFHcFr", "txId": "TugAtCCIQtcUYcFfGVGAHFNfdUjeCokipAn"}, "intrBkSttlmAmt": {"value": 11000, "ccy": "EUR"}, "accptncDtTm": "2025-10-27T17:27:29.878336788Z", "chrgBr": "SLEV", "dbtr": {"nm": "James Allen", "pstlAdr": {"adrLine": ["213 South Street"]}, "id": {"orgId": {"anyBIC": "PRXYITMM"}}}, "dbtrAcct": {"id": {"iban": "GB38UVCRXEHFCFLMQNBTWFSWXISKIW"}, "ccy": "EUR", "nm": "Chloe Williams"}, "dbtrAgt": {"finInstnId": {"bicfi": "ICONGBA1", "clrSysMmbId": {"mmbId": "191919"}, "pstlAdr": {"adrLine": ["897 North Street"]}}}, "cdtrAgt": {"finInstnId": {"bicfi": "ICONGBA0", "clrSysMmbId": {"mmbId": "400302"}, "nm": "Chloe Hughes", "pstlAdr": {"adrLine": ["465 Main Street"]}}, "brnchId": {"id": "iWULDmNwqrZLcrNNmxlELmWDrQGgGdeOavf"}}, "cdtr": {"nm": "Sophia Phillips", "pstlAdr": {"adrLine": ["293 Kingsway"]}, "id": {"orgId": {"lei": "12345678901234567888", "anyBIC": "KJFISESS"}}}, "cdtrAcct": {"id": {"iban": "CZ6508000000192000145399"}}}]}}' -H 'Content-Type: application/json' http://localhost:8080/submit