server.formulas.runFormula
Runs a Business Formula calculation on a set of input arguments.
Syntax
Copy
function server.formulas.runFormula(formulaName: string, input: any, options: any): any
| Parameter | Type | Description |
|---|---|---|
formulaName
|
string | Name of the formula. |
input
|
any | Set of arguments to be processed by the Business Formula calculation. These must match the corresponding formula input set up in the Business Formulae. |
options
|
any | Allows you to set a reference date prior to the current date if you wish to call an earlier version of the formula. |
Return Value
Returns a JSON object containing the details about the calculation. For example:
Copy
{
ErrorMessage: null,
Input: {
calculateInterest: "4.5%",
loanAmount: 10000,
loanPeriod: 100
},
IsSuccess: true,
Result: "4.5%"
}
Examples
In this example:
- We run the predefined MonthlyPayment formula, which uses the NumberOfPayments, InterestRate, and Principal input parameters.
- The values used for the input parameters are: 60 months, 0.0084916 monthly interest rate, and a 30000 USD principal.
- We store the result of the calculation in a variable called monthlyPayment and we display the formula result in a warning message. For details on how to display messages, see ftos.context.response.setMessage.
Copy
let monthlyPayment = server.formulas.runFormula('MonthlyPayment', {'NumberOfPayments': 60, 'InterestRate': 0.0084916, 'Principal': 30000}, null);
ftos.context.response.setMessage('Your monthly payment is: ' + monthlyPayment.Result);