I. Overview
Sometimes the report design involves writing JavaScript codes, but the codes to process some calculations or conversions are particularly complicated, such as date formatting, string interception and replacement. FineReport has built-in functions for processing dates and strings, and they can be called directly in JavaScript.
II. Solution
2.1 Solution 1
Just use "${=formula}" in JS.
For example, we need to display the current date after clicking the button, so write the following JavaScript code in the button's Click event:
var rq='${=today()}';
alert(rq);
2.2 Solution 2
Use the function FR.remoteEvaluate('=formula') to execute formulas.
For example, write the following JavaScript code in the button Click event:
var rq=FR.remoteEvaluate('=format(today(),"yyyy-MM-dd")');
alert(rq);
This can also display the current date.
Using these two methods, you can easily mix JavaScript code with the formulas in FineReport, which greatly improves the efficiency of codes.
2.3 Use parameters
If passing parameters to formula, string concatenation is required.
In the following example, parameter name is "sale" while the parameter value is "Sun"
var area=FR.remoteEvaluate('=sql("FRDemoEN","SELECT Region from Sales_Volume where Salesperson=\''+sale+'\'",1,1)');
alert(area);
Note 1: In order to make function sql() take effect, you need to login the decision-making platform and turn off the Script call formula restriction in Security tab.
Note 2: The mobile terminal App DataAnalyst V9.0 and later versions no longer support the function FR.remoteEvaluate(formula).