This document demonstrates how to call scheduled task APIs in FineReport templates.
Before reading this document, view the following two documents to learn more about API calls:
Introduction to APIs Related to Scheduled Task
Description of Calling APIs Related to Scheduled Tasks
This document demonstrates how to call the Run a Task by Task ID API in a FineReport template.
For details, see the "Plugin Introduction" section of Description of Calling APIs Related to Scheduled Tasks.
1. Log in to the FineDataLink project, choose System Management > Open Platform > Application Management, and click Add. Name the application and set Alternative Authentication to AK/SK Direct Authentication, as shown in the following figure.
2. Click the icon on the right side of the created application, and remember the values of Application ID and Secret Key, as shown in the following figure.
Choose Permission Management > Application. This step illustrates how to assign permission on the Run a Task by Task ID API for the new application, as shown in the following figure.
Locate the scheduled task to be called in Data Development. Copy and record the task ID, as shown in the following figure.
Enter the decision-making platform of FineReport, choose System Management > System Setting > General, and configure FineDataLink API Forwarding.
Enter the FineDataLink project address, for example, http://192.168.101.211:10636/webroot/decision.
Open the GettingStartedEN.cpt template in FineReport, add a button widget to the parameter panel, and add a click event to the button, as shown in the following figure.
The JavaScript code is as follows:
FR.ExecuteWorkByWorkId( { workId: "5820487a-e86d-4412-8d48-312cc4dc0efc", params: { paramName: "paramValue", }, waitForResponse: "true", waitTime: 10000, }, function (error, response) { if (error) { console.error("Request failed:" + error); } else { console.log("The request was successful, and the response data is:" + JSON.stringify(response)); } });
Preview the template and click the button, as shown in the following figure.
Choose O&M Center > Scheduled Task > Execution Record in the FineDataLink project. You can view the latest execution record of the called task, as shown in the following figure.
Objective: Pass the city and country selected from the drop-down list in the FineReport template as parameter values to a scheduled task to trigger its execution.
See the above sections to prepare plugins, create an application in the FineDataLink project, grant permission on the new application, and configure FineDataLink API Forwarding in FineReport.
1. There are two parameters, City and Country, in the scheduled task in FineDataLink, as shown in the following figure.
You can set default values for the parameters to facilitate debugging.
2. There are two drop-down box widgets, City and Country, in the parameter panel of the FineReport template, as shown in the following figure.
1. Record the task ID. For details, see the "Recording the ID of the Task to Be Called" section of this document.
2. Add a button widget to the parameter panel of the FineReport template and add a click event to the button, as shown in the following figure.
var City=_g().getParameterContainer().getWidgetByName("City").getValue();alert(City);var Country=_g().getParameterContainer().getWidgetByName("Country").getValue();alert(Country);FR.ExecuteWorkByWorkId( { workId: "be0e38e8-4ec9-40a5-a92e-5a6c660f2e9b", params: { City:City, Country:Country, }, waitForResponse: "true", waitTime: 10000, }, function (error, response) { if (error) { console.error("Request failed:" + error); } else { console.log("The request was successful and the response data is:" + JSON.stringify(response)); } } );
1. Preview the template and click the button, as shown in the following figure.
2. Choose O&M Center > Scheduled Task > Execution Record in the FineDataLink project. You can view the latest execution record of the called task. Data in the target table is shown in the following figure.
滑鼠選中內容,快速回饋問題
滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。
不再提示
10s後關閉
Submitted successfully
Network busy