You can add custom PHP scripts to your output levels to further manipulate the data in
your report. For example, custom scripts can remove unwanted data, create links to web pages, and
convert rows of data into tables.
Before you start
The Create/Edit Custom Scripts Analytics profile permission must be enabled to access
custom scripts.
When a report with a custom script runs, the report first runs on the server, then the script
is applied to the report’s output. It is important to consider this ordering when creating
custom scripts since this may cause the script to not function as you expect. For instance, when
you view a report with a script that hides certain rows, the total number of records and pages
on the report may be greater than what you see on the report, since these totals are generated
when the report first runs.
PHP scripting language must be used when defining a custom script. PHP is a free, open-source
scripting language and interpreter, similar in many ways to JavaScript and Microsoft’s VBScript.
Like other scripting languages, PHP allows server-side scripting to be embedded inside client
scripting. We recommend creating custom scripts only if you’re familiar with the PHP language
and programming concepts. For documentation and information, see
PHP: Hypertext Preprocessor.
Note: Custom scripts cannot include direct SQL
statements.
Here's what to do
-
Open the report you want to edit.
-
Select the output level you want to add the custom script to from the
Level drop-down list at the top of the report designer.
-
Click the Level tab.
-
Click Custom Scripts. The Custom Script editor opens.
If the output level already has a custom script, the editor displays the custom
script for editing.
-
From the PHP Version drop-down list, choose the php version in which
the script is written and should be executed.
The PHP version of the script and the PHP version chosen in the Custom Script editor
should be same to avoid runtime errors.
The Reports with Custom Scripts report available under lists the custom scripts and the PHP version of the script used in the
report.
-
From the Initialization tab, enter the script executed before the report is processed.
This script is executed when the report starts to process.
Note: If the report
is to be scheduled (see
How You Schedule Reports), add
putenv('TEMPORARY_RNW_CONF_DIRECTORY'); to the Initialization pane to ensure
the custom script runs correctly when recipients open the report.
-
Click the Headers tab.
-
Enter the script that runs during the start process.
This script is called once while passing the column headings. The
$headers parameter is an array that contains the column headers for the
report. For example:
Array
(
[0] => Account ID
[1] => Full Name
)
-
Click the Process tab.
-
Enter the script that runs while the report is generating.
This script is called with each row passing the row data. The $rows
parameter is a nested array, allowing you to return a “table” of data rather than just a row.
Initially, the $rows parameter contains only data in the first row of the
table ($rows[0] [$i]). Each data cell contains a val variable that holds the
value of the data cell. It can also contain a URL variable that contains a link for the data
cell.
-
Click the Finish tab.
-
Enter the script that runs during the exit process.
This script is called after the rows have been processed. The Finish script returns data
in the $exit_obj variable, which is added to the report after each row of
the Process script.
-
Click OK to apply your custom script to your output level.
-
To remove a custom script, click the Level tab, click
Edit, and click Remove. Click
Yes to the removal confirmation.
-
To check the custom script for PHP errors, click the Home tab, click
Views, and select either Report View or
Layout View.
If errors are found in the PHP code, a message displays. You can save the report if
the message shows an error, but the custom script will be disabled when you run the report.
When the problem is corrected and the report is saved again, the custom script will be
enabled.
-
Click Save.
What to do next
After adding a custom script to an output level, we recommend previewing the report using
the Report View and Layout View options on the Home tab’s Views button. When you do so, the
custom script is checked for errors and a message displays if any are found. When troubleshooting
reports, we also recommend that you check if any of the report’s output levels have custom
scripts since these can modify the reports’ appearance and functionality.