---
title: "Report Editor"
url: "https://dev.4hse.com/guides/reports/report-editor"
description: "Guide to the 4HSE report editor: opening and saving a report, the configuration dialog, the Template, Script, Helpers and Partials tabs, and how to test a report with a debug entity."
---

# Report Editor

The **Report editor** is where a [report](/guides/reports/coding-reports/) is written and tested. You edit the template, the script, the helpers and the partials in one window, and see the document that comes out of them without leaving it.

This page describes what the editor shows and what you can do with it. For the language of the report itself (the `onInit` script, the Handlebars template, the helpers), see [Coding Reports](/guides/reports/coding-reports/). For step-by-step use of the editor, from the user’s point of view, see [Customise a report](https://docs.4hse.com/reports/customise-a-report/).

## Open the editor

[Section titled “Open the editor”](#open-the-editor)

There are three ways to open it, described in the user guide:

-   [Modify a report while printing](https://docs.4hse.com/reports/customise-a-report/#modify-a-report-while-printing), from the **Modify** button of the first step of printing;
-   [Modify a report from the file system](https://docs.4hse.com/reports/customise-a-report/#modify-a-report-from-the-file-system), with **Modify** on the `.ht` file;
-   [Create a report](https://docs.4hse.com/reports/customise-a-report/#create-a-report), with **New report** in the file system.

## The window

[Section titled “The window”](#the-window)

The window has four areas:

-   the **toolbar**, at the top;
-   the **preview**, on the left: the document generated by the report;
-   the **tabs**, on the right: **Template**, **Script**, **Helpers** and **Partials**;
-   the **Debugger**, at the bottom: the errors of the last run and the debug entity in use.

![The report editor: preview on the left, the Template tab on the right, the Debugger at the bottom](/_astro/report-editor-window.BKwkpUkZ_Z17sKCH.webp)

The title of the window is the name of the report; until it has one, the name of the file, or _Unnamed report_ for a report that was never saved.

### Toolbar

[Section titled “Toolbar”](#toolbar)

Control

What it does

**Save** (floppy disk, with a menu)

**Save** overwrites the file, **Save as** saves it with another name or in another folder. See [Saving](#saving)

**Configuration** (gear)

opens the [configuration dialog](#configuration)

**Select debug entity**

chooses the item to test the report with. See [Testing](#testing)

**Run**

generates the document with the debug entity and shows it in the preview

**Auto preview**

runs the report again by itself after every change

## Configuration

[Section titled “Configuration”](#configuration)

The **Configuration** dialog holds the [metadata](/guides/reports/report-concepts/#metadata) of the report: the information that does not belong to its code. These are the rules of the editor:

Field

Rule

**Name**

**Required.** A report cannot be saved without it

**Tag**

Optional. A tag is 2 to 20 characters long: lowercase letters, numbers, underscores and hyphens, no spaces

**Launch points**

A report with no launch points never appears in a picker. See [Launch points](/guides/reports/report-concepts/#launch-points)

**Country**, **Language**

See [Country and language](/guides/reports/report-concepts/#country-and-language)

**Output type**

**HTML**, **CSV** or **Plain text**. It also sets how the Template tab is highlighted: as HTML for **HTML**, as plain text for the others

**Description** is optional.

**Confirm** applies the changes to the report being edited: they are saved to the file when you save it. **Cancel** discards them.

**Example.** The configuration of the report “Material resource badge (QR)”, with every field filled in:

Field

Value

**Name**

`Material resource badge (QR)`

**Description**

`Printable CR80 badge with QR code, name and code — equipment, substances, work environments`

**Tag**

`badge`, `qr`

**Launch points**

`equipment`, `substance`, `work_environment`

**Country**

United Kingdom

**Language**

English (United Kingdom)

**Output type**

**HTML**

With this configuration the report appears in the report picker of a piece of equipment, a substance and a work environment, for people working in the United Kingdom and in English.

## The tabs

[Section titled “The tabs”](#the-tabs)

Tab

What it contains

**Template**

the [template](/guides/reports/coding-reports/#template)

**Script**

the [script](/guides/reports/coding-reports/#loading-data-oninit), with the `onInit` function

**Helpers**

the [report-specific helpers](/guides/reports/coding-reports/#report-specific-helpers)

**Partials**

the [partials](/guides/reports/report-concepts/#partials) included in the template, one per row

The **Script** and **Helpers** tabs mark syntax errors in the margin of the editor, as you type.

**Example.** A minimal report shows the name of an item in capitals, with a helper:

Tab

Content

**Template**

`<h1>{{upper name}}</h1>`

**Script**

`async function onInit() { return { name: 'Pump 1' }; }`

**Helpers**

`var helpers = { upper: function (text) { return String(text).toUpperCase(); } };`

**Partials**

none

The result is a title that reads `PUMP 1`.

### Partials

[Section titled “Partials”](#partials)

Each row of the **Partials** tab has an **Alias**, the file and a **Select** button:

1.  Add a row.
2.  Click **Select** and choose the file. The picker shows the `.ht`, `.html` and `.hdoc` files, starting from the project the report belongs to.
3.  The **Alias** is filled in with the name of the file without its extension, if you have not typed one. Change it to the name you want to use in the template.
4.  In the **Template**, write `{{> alias}}` where the piece has to appear.

A row with no alias or no file is ignored when the report is saved. What a partial is and how it uses the data of the report is explained in [Partials](/guides/reports/report-concepts/#partials).

## Testing

[Section titled “Testing”](#testing)

To test a report you first choose the **debug entity** (see [Report Concepts](/guides/reports/report-concepts/#debug-entity)):

1.  Click **Select debug entity**.
2.  If the report has more than one launch point, choose the one you want to test: the report sees it as `this.runtime.target`.
3.  Choose the item. The list shows only items of the type that launch point works on: a piece of equipment for `equipment`, an office for `office.equipment_list`. A launch point that has no item behind it (for example `person_list`) needs no choice.

Until you choose a debug entity the preview shows a message asking for one, and **Run** does nothing. Once chosen, the Debugger header shows the entity and the launch point in use, and a **Clear** button that drops them.

Click **Run** to generate the document. The editor first checks the syntax of the template (as Handlebars reads it), of the script and of the helpers: if there is an error the report does not run, the preview keeps the last result and the error is listed in the Debugger. Otherwise the report runs as described in [How a report runs](/guides/reports/report-concepts/#how-a-report-runs), with the debug entity as its `this.runtime`, and the result appears in the preview, in a document of its own, so that a full page with `<html>`, `<head>` and `<body>` looks as it will when printed.

**Example.** With the debug entity of a pump, a report with launch points `equipment` and `substance` is tested like this:

1.  Click **Select debug entity**.
2.  Choose the launch point `equipment`.
3.  Choose the pump from the list of equipment.
4.  Click **Run**: the document appears in the preview.

### Debugger

[Section titled “Debugger”](#debugger)

Each error is a row with four columns:

Column

Content

**Time**

when the error happened

**Place**

where: `script`, `helpers` or `template`

**Name**

the type of error, for example `SyntaxError` or `ReferenceError`

**Message**

the message of the error

**Example.** If in the script you write `return { name: foo };` by mistake, without defining `foo`, the Debugger lists a row:

Time

Place

Name

Message

10:42:03

`script`

`ReferenceError`

`foo is not defined`

The report does not generate the document until the error is fixed.

### Auto preview

[Section titled “Auto preview”](#auto-preview)

With **Auto preview** on, the report runs by itself a moment after the last change to the template, the script, the helpers, the partials, the configuration or the debug entity. The Debugger is cleared before each run, so it lists only the errors of the report as it is now. It does nothing until a debug entity is chosen.

## Saving

[Section titled “Saving”](#saving)

Click **Save** to open the menu:

-   **Save as** opens the file picker. It shows only the folders you can write to, and saves a `.ht` file. After the first save, the editor keeps working on the new file.
-   **Save** overwrites the file the editor is working on: the file the report was opened from, or the one chosen with **Save as**. It is not available for a new report that was never saved.

A report that comes from outside the project (the 4HSE catalogue or a partner’s) and was opened from the print wizard cannot be overwritten: **Save** is disabled until you use **Save as** in a folder of the project. The original stays as it was, and the printing uses your copy when you choose **This project** in the report picker (see [Choose a report](https://docs.4hse.com/reports/choose-a-report/)).

A report cannot be saved without a name: the editor asks for it and does not save.

When a report is saved, the keys the editor does not know are kept as they are.

This site is protected by reCAPTCHA and the Google [Privacy Policy](https://policies.google.com/privacy) and [Terms of Service](https://policies.google.com/terms) apply.