> ## Documentation Index
> Fetch the complete documentation index at: https://developers.scoutworks.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Trustee board pack

> The risk register, premises audits, fire safety actions and the budget position on four tabs, refreshed before each trustee meeting. For group chairs and secretaries.

> [!NOTE]
>
> * **For:** trustees and group admins
> * **You get:** the risk register, overdue premises audits, open fire-safety actions and this year's budgets, in one workbook
> * **Time:** about fifteen minutes
> * **Scopes:** `compliance:read` and `accounting:read`

Trustees look at the same things at every meeting: the biggest risks, what the premises still need, and how the money stands against the budget. This recipe puts all of it in one Google Sheet, on four tabs:

* **Risks**: the active risks, highest score first, with the reviews that are overdue.
* **Premises**: the latest Safe Scouting audit of each premises, with its open and overdue actions.
* **Fire safety**: each current fire risk assessment, with its open and overdue actions.
* **Budgets**: this accounting year's budgets, with what each has spent or raised.

It uses Google Apps Script. It takes about ten minutes. To build the same tabs in Excel, see [Excel instead](#excel-instead).

## 1. Add the script

In your Google Sheet, choose **Extensions → Apps Script**. Delete what is there, paste the script below and choose **Save**.

```javascript Code.gs theme={null}
// Scoutworks → trustee board pack. https://developers.scoutworks.app/recipes/trustee-board-pack

const BASE = 'https://api-demo.scoutworks.app/api/v1';

function buildBoardPack() {
  const today = Utilities.formatDate(new Date(), 'Europe/London', 'yyyy-MM-dd');

  // Risks: active only, highest score first.
  const risks = readAll('/risk-register?status=active');
  risks.sort(function (a, b) { return b.riskScore - a.riskScore; });
  write('Risks', ['Risk', 'Category', 'Score', 'Tier', 'Owner', 'Next review', 'Review overdue'],
    risks.map(function (r) {
      return [
        r.title === null ? 'Safeguarding risk (title not shown)' : safe(r.title),
        r.category.replace(/_/g, ' '),
        r.riskScore,
        r.riskTier,
        r.ownerRoles === null ? 'No owner' : (r.ownerRoles.join(', ') || 'Owner has left'),
        r.nextReviewDue ? r.nextReviewDue.slice(0, 10) : '',
        r.reviewOverdue ? 'Yes' : '',
      ];
    }));

  // Premises: the newest audit of each premises.
  const latest = new Map();
  readAll('/premises-audits').forEach(function (a) {
    const seen = latest.get(a.title);
    if (!seen || (a.undertakenOn || a.createdAt) > (seen.undertakenOn || seen.createdAt)) latest.set(a.title, a);
  });
  write('Premises', ['Premises', 'Status', 'Audited', 'Next audit due', 'Audit overdue', 'Open actions', 'Overdue actions'],
    Array.from(latest.values()).map(function (a) {
      return [
        safe(a.title),
        a.status === 'completed' ? 'Completed' : 'In progress',
        a.undertakenOn || '',
        a.nextAuditDueOn || '',
        a.nextAuditDueOn && a.nextAuditDueOn < today ? 'Yes' : '',
        a.actions.open,
        a.actions.overdue,
      ];
    }));

  // Fire safety: current assessments only, worst first.
  const fire = readAll('/fire-risk-assessments').filter(function (f) { return !f.superseded; });
  fire.sort(function (a, b) { return b.actions.overdue - a.actions.overdue; });
  write('Fire safety', ['Premises', 'Status', 'Assessed', 'Next review', 'Open actions', 'Overdue actions', 'Next action due'],
    fire.map(function (f) {
      return [
        safe(f.title),
        f.status.replace(/_/g, ' '),
        f.assessedOn,
        f.nextReviewOn || '',
        f.actions.open,
        f.actions.overdue,
        f.nextActionDueOn || '',
      ];
    }));

  // Budgets: the accounting year that today falls in.
  const year = readAll('/accounting-periods').filter(function (p) {
    return !p.isHistoric && p.startDate <= today && today <= p.endDate;
  })[0];
  const budgets = year ? readAll('/budgets?periodId=' + year.id) : [];
  write('Budgets', ['Budget', 'Kind', 'Amount (£)', 'Spent or raised (£)', 'Remaining (£)'],
    budgets.map(function (b) {
      return [
        safe(b.name),
        b.type === 'expense' ? 'Spending limit' : 'Income target',
        Number(b.amount),
        Number(b.spent),
        Number(b.remaining),
      ];
    }));
  if (year) SpreadsheetApp.getActive().getSheetByName('Budgets').getRange('G1').setValue(year.name);
}

// Replaces a tab's contents with a header row and rows.
function write(name, header, rows) {
  const book = SpreadsheetApp.getActive();
  const sheet = book.getSheetByName(name) || book.insertSheet(name);
  sheet.clearContents();
  const table = [header].concat(rows);
  sheet.getRange(1, 1, table.length, header.length).setValues(table);
  sheet.getRange(1, 1, 1, header.length).setFontWeight('bold');
  sheet.setFrozenRows(1);
}

// Every item in a list, following nextCursor to the last page.
function readAll(path) {
  const items = [];
  let cursor = null;
  do {
    let url = BASE + path + (path.indexOf('?') === -1 ? '?' : '&') + 'limit=200';
    if (cursor) url += '&cursor=' + encodeURIComponent(cursor);
    const body = fetchScoutworks(url);
    items.push.apply(items, body.data);
    cursor = body.nextCursor;
  } while (cursor);
  return items;
}

// Calls the API. Waits and tries again if the rate limit is reached.
function fetchScoutworks(url) {
  const apiKey = PropertiesService.getScriptProperties().getProperty('SCOUTWORKS_API_KEY');
  if (!apiKey) throw new Error('Add SCOUTWORKS_API_KEY in Project Settings → Script Properties.');
  for (let attempt = 0; attempt < 3; attempt++) {
    const res = UrlFetchApp.fetch(url, {
      headers: { Authorization: 'Bearer ' + apiKey },
      muteHttpExceptions: true,
    });
    const body = JSON.parse(res.getContentText());
    if (res.getResponseCode() === 200) return body;
    if (res.getResponseCode() === 429) {
      Utilities.sleep((body.retryAfter || 30) * 1000);
      continue;
    }
    throw new Error(body.error.code + ': ' + body.error.message);
  }
  throw new Error('Scoutworks is still busy. Try again in a minute.');
}

// Stops a name that starts with = + - or @ from running as a formula.
function safe(value) {
  const text = String(value);
  return /^\s*[=+\-@]/.test(text) ? "'" + text : text;
}
```

## 2. Add your key

In the script editor, choose **Project Settings** (the cog), then **Script Properties → Add script property**. Property: `SCOUTWORKS_API_KEY`. Value: the [sandbox key](https://developers.scoutworks.app/guides/sandbox.md) to try it, or your own key. Choose **Save script properties**.

## 3. Run it

Choose **buildBoardPack** in the toolbar and press **Run**. Google asks for permission the first time. Then open the four tabs.

To refresh it every morning, choose **Triggers** (the clock), then **Add Trigger**. Function: `buildBoardPack`. Event source: **Time-driven**. Type: **Day timer**. Time: **6am to 7am**. A daily run matters here: a review or action that becomes overdue because a date passed is not a change the API reports, so only a fresh read shows it.

## 4. Switch to your group

Change `api-demo.scoutworks.app` to `api.scoutworks.app`, and replace the sandbox key with your own. Your key needs `compliance:read` and `accounting:read`. Give it no other scope: the board pack needs no names.

## What is not in the pack

* **No names.** A risk's owner shows as the roles they hold, for example `trustee`. A safeguarding risk shows no title, because a title can describe a concern.
* **No descriptions, mitigations, audit answers or findings' text.** The pack gives counts and dates. Open the risk or audit in Scoutworks to read the detail.
* **Bank balances.** To add them, read `GET /bank-accounts` with the same key and add a fifth tab.

## Excel instead

Use the full version in [Events in Excel](https://developers.scoutworks.app/recipes/excel.md), with your key and these addresses in place of the events address. Make one query for each tab.

| Tab | Address |
| - | - |
| Risks | `https://api-demo.scoutworks.app/api/v1/risk-register?status=active` |
| Premises | `https://api-demo.scoutworks.app/api/v1/premises-audits` |
| Fire safety | `https://api-demo.scoutworks.app/api/v1/fire-risk-assessments` |
| Accounting years | `https://api-demo.scoutworks.app/api/v1/accounting-periods` |
| Budgets | `https://api-demo.scoutworks.app/api/v1/budgets` |

The budgets list holds every accounting year. Filter its `periodId` column to the `id` of this year in the accounting years query. The [API reference](https://developers.scoutworks.app/api-reference/introduction.md) lists every field.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.