Overview
Problem
During export file name customization by JS, you can customize an export button for exporting files with custom names by JS on the parameter panel of a template. However, it is cumbersome for you to achieve the same export function in multiple templates by repetitively writing JS codes. Therefore, you can predefine an export button that can be directly dragged to the parameter panel for use whenever needed, as shown in the following figure.
Implementation Method
You can customize an export button to which a JS event is added in Widget Management to realize the export function.
Example
Predefined Button
1. Choose Server > Widget Management on the menu bar of the designer, as shown in the following figure.
2. Create a widget and set attributes for the widget, as shown in the following figure.
① Click + to create a widget.
② Double-click Predefined WidgetX and modify the name to Export.
③ Select Button Widget from the drop-down list of Select Widget.
④ Set Widget Name to export.
⑤ Set Button Type to Common and set Button Name to Export.
3. Click Event, add parameters and the JS code, and then click OK in the lower left corner, as shown in the following figure.
The following shows the parameters.
Set the value of the parameter servletURL to the formula servletURL.
Set the value of the parameter reportName to the formula reportName.
Set the value of the parameter exportName to the formula indexofarray(split(indexofarray(REVERSEARRAY(split(reportName,"/")),1),".c"),1)+"_"+format(now(),"yyyyMMddHHmm"). This formula is used to customize the file name.
The JavaScript code is as follows.

// Define the report URL by obtaining the path and name of the corresponding template with built-in parameters servletURL and reportName.
var url=servletURL+"?viewlet="+reportName;
// Traverse the parameter panel widgets to obtain their corresponding values.
$.each(this.options.form.name_widgets,function(i,item) {
if(item.options.type!== 'label'&&item.getName()!="PARA"&&item.getName()!="SEARCH"&&item.getName()!="EXPORT") {
url+="&"+item.getName()+"="+item.getValue();
}
});
// Add printing parameters to the URL.
url+="&format=excel&extype=simple&__filename__="+exportName;
url += "&format=excel&extype=simple&filename=" + exportName;window.location = encodeURI(encodeURI(url)); // Encode and export the file.
Button Use
Open a template, for example, the built-in template GettingStartedEN.cpt in %FR_HOME%\webapps\webroot\WEB-INF\reportlets.
1. On the toolbar of the parameter panel, click the small triangle icon to view the custom export button, press the button, and drag the button to the parameter panel for use, as shown in the following figure.
2. Save the template and click Pagination Preview. After you query the report content, click the Export button to export the Excel file. The following figure shows the effect.

Template Download
For details, you can download the template Predefined Export Button by JS.cpt.