Creating JavaScript reports
JavaScript reports allow you to loop through a list of records and use server-side JavaScript (or formulas) to generate output. You can also invoke complex logic and run queries using the Platform query API.
To create a JavaScript based report, do the following:
- Create a new report by doing any of the following:
- Click New Report in the Reports tab in the default Platform application.
- Open an object definition, select Reports from the ribbon, and click New Report.
- Open any page containing a section with a report link and click New Report in that section's header.
- Select an object to Report On and the select JavaScript as your Report Type.
- Specify a Report Name and provide description if required.
- In the Report Name
Template field, specify a name for the report template. You can
use date, month, and/or year tokens. If you do not input any value, the name of
the report is used as the file name by default. Special characters are converted
to underscore in file names.Note: You can see the JavaScript report names reflected when you send report emails, create new batch jobs, use report filters, and use report tokens in Document template
- Define a JavaScript report:
- Select the Content Type of the output: Plain Text, HTML, XML Document, or CSV Spreadsheet.
- Optionally define JavaScript to generate the report header.
- Select a view to use to loop through the selected object's records.
- Define JavaScript to be executed for each record in the loop.
- Optionally define JavaScript to generate the report footer.
Inside the header, body and footer you can use the rbv_api.print() or rbv_api.println() methods to generate the report's output.
The following example reports a list of Lead records:
Header:
rbv_api.println("Hot Leads\n=========================");
Body:
if ("{!lead_type#code}"=="HOT") rbv_api.println("{!name#text}");
This will generate a text report that looks like:
Hot Leads ========================= Per Hanseon jose del pino sawyer joe Todd Geist Bob Myers
If you are using complex business logic to process a report's records, consider running the report asynchronously using a batch job.
- Optionally specify report filters for the object. For example, if you are generating a report on an object that stores your customer information, then you can apply a filter that direct Platform to include only customers from Asia in the report.
- Specify the access permissions (see Access control).
- Click Save.