Overview
When designing reports, you may need to write JavaScript code to handle complex calculations or conversions, such as date formatting, string extraction, and string replacement. If you want to display the current date in the format 2017-02-24 using native JavaScript code, the following code is required:
var da = new Date();
var year = da.getFullYear();
var month = da.getMonth() + 1;
var day = da.getDate();
if (month < 10) month = '0' + month;
if (day < 10) day = '0' + day;
var rq = year + '-' + month + '-' + day;
alert(rq);
Although the above code achieves the desired result, the code is lengthy and lacks reusability. If a different format is needed, the code must be modified again. Therefore, is there a simpler way to write JavaScript code in FineReport? FineReport provides built-in date formatting functions, which can be directly called in JavaScript code.
This document introduces how to call FineReport formulas in JavaScript code.
Method
Method One
In JavaScript, you can use FineReport's built-in formulas directly by using the syntax ${=Formula}. For example, to get the current date, you can use the built-in formula today().

var rq='${=today()}';
alert(rq);
If you want to click a button to display the current date, you can enter the above code in the Click event of the button.
You can preview the report to obtain the current date.
Method Two
You can execute functions by using the remote formula FR.remoteEvaluate('=Formula') provided by FineReport. To meet the same needs described in section "Overview", the JavaScript code is as follows:

var rq = FR.remoteEvaluate('=format(today(), "yyyy-MM-dd")');
alert(rq);
If you want to click a button to display the current date, you can enter the above code in the Click event of the button.
In FineReport, you only need to write one line of code to achieve the same functionality as multiple lines of native JavaScript code.
When the formula execution requires parameters, you need to concatenate the formula string accordingly. For example, if the parameter name is sale and the parameter value is Mike, the code is as follows:
var region=FR.remoteEvaluate('=sql("FRDemo","SELECT Region FROM Sales_Volume WHERE Salesperson=\''+sale+'\'",1,1)');
alert(region);

By using these two methods, you can easily mix JavaScript code with FineReport formulas, significantly improving development efficiency.
If the use of certain formulas causes the error message "This formula is forbiddenSQL", it is because the platform has enabled Forbid Script to Call Formula. You can disable this option if needed, but doing so may introduce security risks. For details, see Security Protection.