Report rendering customisation
The report debugging option, post-processing scripts with six worked examples, and the fields of a report template.
This reference covers the ways to change how a report renders after its data is selected: post-processing scripts on one report, and report templates shared by many. It is for administrators who know JavaScript and JSON. Only administrator can read or edit the script fields.
How to read this page
Servicely renders reports with Highcharts. The template and theme of a report produce a Highcharts options object. A post-processing script changes that object for one report. A report template defines it for every report that uses the template. Both use the same options, in a slightly different form.
You turn on report debugging in your user settings to see the options of any report you view. You set post processing with Post processing and Configuration on one report. You manage report templates under Reporting → Reports → All report templates, and they apply to every report whose Template points to them.
Report debugging
Turn on Report debugging information in your user settings. When you then view a report, it returns the JSON options passed to the reporting engine. Use it with post processing to see which part of the options object to change.
Post-processing scripts
To post-process a report, set Post processing to Yes and write the script in Configuration. The options are available as the variable options, and the script ends by returning options.
Example 1: Currency prefix and decimals on a number report
This script shows the value with a currency prefix and two decimal places.
options.servicely.before = function(_, hc) {
hc.setOptions({
lang: {
decimalPoint: '.',
thousandsSep: ','
}
});
};
options.plotOptions.series.dataLabels.format = '${point.y:,.2f}';
options;
Example 2: Labels on top of grouped columns
This script adds a styled data label above each column of a grouped column chart.
let dataLabelStyling = {
"fontFamily": "\"Source Sans Pro\", Helvetica, sans-serif",
"color": "#495674",
"fontSize": "13px",
"fontWeight": "500",
"fontStyle": "normal"
};
options.plotOptions.column.dataLabels = {};
options.plotOptions.column.dataLabels.style = dataLabelStyling;
options.plotOptions.column.dataLabels.enabled = true;
options;
Example 3: Percentage and count on pie chart labels
This script totals the series, then appends each slice’s percentage and count to its label.
let totalCount = 0;
if (options.series.length > 0) {
options.series[0].data.forEach(_elem => totalCount += _elem.y);
options.series[0].data.forEach(_elem => {
let percentage = Math.round((_elem.y / totalCount) * 1000) / 10;
_elem.name = _elem.name + ": " + percentage + "% (" + _elem.y.toString() + ")";
});
}
options;
Example 4: One total across child tables
A report on a parent table such as Work or ITSMWork returns one count per child table. This script merges them into a single total and keeps the drill-down record IDs.
let seriesData = options.series[0].data;
let grandTotal = 0;
let allRecordIDsArr = [];
seriesData.forEach(function(_elem) {
grandTotal += _elem.y;
allRecordIDsArr = allRecordIDsArr.concat(_elem.ddids);
});
let newDataSet = [];
newDataSet.push(seriesData[0]);
newDataSet[0].y = grandTotal;
newDataSet[0].ddids = allRecordIDsArr;
options.series[0].data = newDataSet;
options;
Example 5: Data table under the chart
This script always shows a table of the numbers under the chart.
options.servicely.before = function(_, hc) {
hc.setOptions({});
};
options.exporting = {};
options.exporting.showTable = true;
options;
Example 6: Readable labels for boolean groups
A report on SLAs grouped by the SLAMet flag shows the labels “true” and “false”. This script renames them “SLA met” and “SLA breached”.
if (options.series.length > 0) {
options.series[0].data.forEach(_elem => {
if (_elem.name == "true") {
_elem.name = "SLA met";
} else if (_elem.name == "false") {
_elem.name = "SLA breached";
}
});
}
options;
Report template fields
A report’s Template field, under Appearance, points to a report template. Create your own under Reporting → Reports → All report templates. Start from a default template close to what you need, copy it and change the copy.
| Field | Type | Required | Behaviour | Purpose |
|---|---|---|---|---|
| Name | String | No | Shown in the Template picker on the report. | Identifies the template, for example “Other - custom number with label”. |
| Category | Choice | No | The template category the template appears under on the report, for example Other. | |
| Description | String | No | More detail about the template. | |
| Default | Boolean | No | When on, the template is used by any report that has no template set. | |
| Template | Code | No | The Highcharts options of the template. |
Example: currency prefix in a report template
The template form of Example 1 changes two parts of the template. First, the servicely option:
servicely: {
before: function(Report, Highcharts) {
Report.singleDataPointAggregation(this);
Highcharts.setOptions({
lang: {
decimalPoint: '.',
thousandsSep: ','
}
});
}
}
Then the format of the series data labels, inside plotOptions:
plotOptions: {
series: {
dataLabels: {
format: '${point.y:,.2f}'
}
}
}
Keep the other properties of plotOptions, series and dataLabels that the template already has.