Multi-step Calculation
The multi-step calculation can be used for complicated loan calculations (in assignments ONLY).
Each step is a calculation assigned to an intermediate variable, which can be used in the following steps.
To avoid name conflict, the intermediate variable's name should NOT start with var, which is internally used by the portal framework.
The variable name of the last step must be final, which holds the final calculated value.
Status
Release Available | Status | Framework Name |
---|---|---|
2.8.1 | Current | TBC |
Code JSON
Copy
"assignments": [{
"field": "$this.attr(totalAmount);",
"mathValue": [
"x = …",
"y = …",
"final = …" ] }]
Implementation Example
- Users can specify a loan amount between 75000 and 150000.
- Interest changes with the different loan amounts.
- Total amount = Loan Amount * (1 + selected interest rate)
variable | 1 year | 3 | 5 | 8 | 10 | |
---|---|---|---|---|---|---|
Loan amount < 100000 (50%) | 4.2 | 4.4 | 4.4 | 4.5 | 4.8 | 5 |
Loan amount < 120000 (60%) | 4.4 | 4.6 | 4.6 | 4.7 | 5 | 5.2 |
Loan amount < 140000 (70%) | 4.6 | 4.8 | 4.8 | 4.9 | 5.2 | 5.4 |
Code JSON
Copy
"fields": [{
"fieldName": "loanAmount",
"fieldUi": {
"fieldType": "range", "label": "Loan Amount",
"rangeOptions": { "min": 75000, "max": 150000, "step": 1000 },
"tickMarks": [{
"text": "60%",
"position": "@mathjs{ (120000 - 75000) / (200000 - 75000) };"
}, {
"text": "70%",
"position": "@mathjs{ (140000 - 75000) / (200000 - 75000) };"
}]
}},
Code JSON - for 50%
Copy
{ "fieldName": "interest50",
"fieldUi": {
"fieldType": "picklist", "label": "Interest (50%)", "defaultValue": "variable",
"selectOptions": [
{ "optionText": "4.2% (Variable)", "optionValue": "variable" },
{ "optionText": "4.4% (1 Year)", "optionValue": "1y" },
{ "optionText": "4.4% (3 Years)", "optionValue": "3y" },
{ "optionText": "4.5% (5 Years)", "optionValue": "5y" },
{ "optionText": "4.8% (8 Years)", "optionValue": "8y" },
{ "optionText": "5.0% (10 Years)", "optionValue": "10y" }
]}},
{ "fieldName": "interest60",…},
{ "fieldName": "interest70",…}
Code JSON - appearance
Copy
"appearance": {
"renderFields": {
"interest50": "($this.attr(loanAmount); / 200000) < 0.5",
"interest60": "($this.attr(loanAmount); / 200000) >= 0.5 and ($this.attr(loanAmount); / 200000) < 0.6",
"interest70": "($this.attr(loanAmount); / 200000) >= 0.6"
}
Code JSON - fieldChange Handler
Copy
"generalHandlers": { "fieldChange": {
"loanAmount, interest50, interest60, interest70": {
"assignments": [{
"field": "$this.attr(totalAmount);",
"mathValue": [
"i50 = $this.attr(interest50);",
"i60 = $this.attr(interest60);",
"i70 = $this.attr(interest70);",
"r50 = i50 == \"variable\" ? 4.2 : (i50 == \"1y\" ? 4.4 : (i50 == \"3y\" ? 4.4 : (i50 == \"5y\" ? 4.5 : (i50 == \"8y\" ? 4.8 : 5.0))))",
"r60 = i60 == \"variable\" ? 4.4 : (i60 == \"1y\" ? 4.6 : (i60 == \"3y\" ? 4.6 : (i60 == \"5y\" ? 4.7 : (i60 == \"8y\" ? 5.0 : 5.2))))",
"r70 = i70 == \"variable\" ? 4.6 : (i70 == \"1y\" ? 4.8 : (i70 == \"3y\" ? 4.8 : (i70 == \"5y\" ? 4.9 : (i70 == \"8y\" ? 5.2 : 5.4))))",
"perct = $this.attr(loanAmount); / 200000",
"rate = perct < 0.5 ? r50 : (perct < 0.6 ? r60 : r70)",
"final = $this.attr(loanAmount); * (1 + rate/100)" ]}
]}