Write your first private plugin

A private plugin is one your company writes for itself - a card with data from your own systems, a small tool for your team, a whiteboard. You upload it to your own instance; nobody else sees it. This tutorial builds one real plugin, the Task Radar, from an empty folder, with the complete code in every step. Plan an hour, and keep the Cookbook open in a second tab: it lists every place, every right and every data source.

What you build

The rules in one breath: a plugin sees and changes only what the person in front of it may - and only what the administrator allowed at installation. It has no database of its own (it keeps small documents through the SDK), no access to cookies or to the page around it, and it can be removed completely. Resourcecloud runs none of your code on its server: your files run in the browser, in a sandbox.

Before you start

JavaScript in 3 minutes

If you write JavaScript every day, skip this. Otherwise these are the only things the listings use:

1. The manifest

Make a folder my-plugin. Every plugin starts with the file rcplugin.json. It says what the plugin is, what it wants to be allowed, and where it shows up. Version 0.1:

{
  "id": "com.mycompany.radar",
  "name": "Task Radar",
  "version": "0.1.0",
  "slots": [
    { "slot": "menu.page", "entry": "radar.html", "label": "Task Radar" }
  ]
}
FieldMeaning
idThe plugin's name for good - lower case, dots, hyphens, like a reversed web address of your company. Nobody else may use it, and an update must keep it.
nameWhat people see in lists and the menu. Plain text, or { "en": "Task Radar", "de": "Task-Radar" } for several languages.
versionThree numbers. Every new upload must be higher than the installed one (0.1.0 → 0.2.0).
slotsThe places the plugin shows up. menu.page = a page of its own in the menu under Plugins. entry is the HTML file shown there (a path inside your folder), label the menu text. There are four more places (task card, project tab, dashboard card, settings page): the cookbook lists them all.

There is no permissions yet: the plugin asks for nothing and can therefore do nothing but show its own files. That is how every plugin starts.

2. The first page

Next to the manifest, two files. radar.html is the page:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>Task Radar</title>
</head>
<body>
  <div id="root">Loading ...</div>
  <script src="_rc/sdk.js"></script>
  <script src="radar.js"></script>
</body>
</html>

and radar.js is the code:

// radar.js, version 0.1: greet the person
rc.ready.then(function (ctx) {
  document.getElementById('root').textContent = 'Hello ' + ctx.user.name + '!';
});

3. Pack, upload, install

A package is a .zip or .tar.gz with rcplugin.json at the top. The plain way:

cd my-plugin
zip -r ../radar-0.1.0.zip rcplugin.json radar.html radar.js
# rcplugin.json must be at the TOP of the zip, not inside a folder. Check with:  unzip -l ../radar-0.1.0.zip

The better way, with the tool from plugin-sdk/. It makes the checks an instance makes at upload (so you hear of a mistake first) and writes the same bytes every time:

# once: get the tool (it is a plain Node.js script, no installation)
cd plugin-sdk
node bin/rc-plugin.js check ../my-plugin            # the checks an instance makes at upload
node bin/rc-plugin.js pack  ../my-plugin --out ..   # writes com.mycompany.radar-0.1.0.zip next to the folder
  1. As RC Admin open Settings → Plugins, tab Upload. Choose your zip, click Upload and check.
  2. A consent dialog opens. It says private plugin, not reviewed (it is yours; nobody at Ontaric looked at it), shows the SHA-256 of your file, lists the rights the plugin asks for (none yet) and where it shows up.
  3. Click Install and allow. A new menu section Plugins appears with Task Radar. Open it: Hello and your name. You have a plugin.

Nothing is live before that click. Close keeps the upload waiting in the list (Review and install / Discard); an upload nobody confirms is removed after a day. If the check complains, the message names the problem (see the table at the end).

4. Show your tasks

The plugin can read data of Resourcecloud through the REST API - as the person who looks at it, never more. Replace radar.js with version 0.2:

// radar.js, version 0.2: list my open tasks
rc.ready.then(function (ctx) {
  var root = document.getElementById('root');
  root.textContent = '';

  var url = '/tasks?done=0&assigned_worker=' + encodeURIComponent(ctx.user.username) + '&limit=20';
  rc.api.get(url).then(function (tasks) {
    tasks.forEach(function (task) {
      var line = document.createElement('div');
      line.textContent = '#' + task.ID + ' ' + task.work_desc + ' (due ' + task.due + ')';
      root.appendChild(line);
    });
  }, function (err) {
    root.textContent = 'Error: ' + err.message;
  });
});

Upload this as it is, and you see Error: ... instead of tasks. That is the point of the consent dialog: the plugin never asked for tasks:read, so the platform refused. Ask for it in the manifest (version 0.2):

{
  "id": "com.mycompany.radar",
  "name": "Task Radar",
  "version": "0.2.0",
  "permissions": ["tasks:read"],
  "slots": [
    { "slot": "menu.page", "entry": "radar.html", "label": "Task Radar" }
  ]
}
  1. Pack and upload again. The dialog now says Update and marks the new right new: "Read tasks", risk medium. The old version keeps running until you click Update and allow.
  2. Reload the page: your open tasks. A colleague who opens the same plugin sees their tasks.

5. Search, sort, remember

Now the real thing. Here are the complete final files. radar.html - the page now also loads a stylesheet:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>Task Radar</title>
  <link rel="stylesheet" href="radar.css">
</head>
<body>
  <div id="root"></div>
  <script src="_rc/sdk.js"></script>
  <script src="radar.js"></script>
</body>
</html>

radar.js - read it top to bottom; the notes below explain the parts:

/*
 * Task Radar - the menu page. Needs: tasks:read (the list), storage:user (remembers the "only overdue" switch).
 *
 *   rc.ready                          -> the context: who is looking, language, theme
 *   rc.api.get('/tasks?...')          -> the person's tasks, as the person may see them
 *   rc.storage.get/set('user', ...)   -> a small document that belongs to this person and this plugin
 *   rc.ui.navigate('/edit_workflow?workid=ID')  -> opens the task in the app
 */
(function () {
  'use strict';

  var TEXT = {
    en: { title: 'Task Radar', search: 'Search in titles', onlyLate: 'only overdue', count: ' open tasks', task: 'Task', type: 'Type', due: 'Due', none: 'Nothing to show.',
      overdue: 'overdue', failed: 'Something went wrong: ', noRight: 'This plugin was not allowed to do that: ' },
    de: { title: 'Task-Radar', search: 'In Titeln suchen', onlyLate: 'nur überfällige', count: ' offene Tasks', task: 'Task', type: 'Typ', due: 'Fällig', none: 'Nichts zu zeigen.',
      overdue: 'überfällig', failed: 'Es ist etwas schiefgegangen: ', noRight: 'Das darf dieses Plugin nicht: ' }
  };

  var t, ctx, root, tasks = [], prefs = { onlyLate: false };
  var table, count, search, lateBox;

  /** Makes an element. The text goes in with textContent: whatever it contains, it is shown as text and never run as markup. */
  function el(tag, text, cls) {
    var e = document.createElement(tag);
    if (text !== undefined) { e.textContent = text; }
    if (cls) { e.className = cls; }
    return e;
  }

  /** Today as YYYY-MM-DD, to compare with a task's due date (the API gives dates in the same form, so plain string comparison works). */
  function today() {
    var d = new Date();
    return d.getFullYear() + '-' + ('0' + (d.getMonth() + 1)).slice(-2) + '-' + ('0' + d.getDate()).slice(-2);
  }

  function explain(err) {
    return err.code === 'plugin_permission' ? t.noRight + err.permission : t.failed + (err.message || err);
  }

  /** Draws the table from the tasks that pass the filters. Called again whenever the search text or the switch changes. */
  function draw() {
    var q = search.value.trim().toLowerCase(), now = today();
    var shown = tasks.filter(function (task) {
      if (q && String(task.work_desc).toLowerCase().indexOf(q) === -1) { return false; }
      if (prefs.onlyLate && !(task.due && task.due < now)) { return false; }
      return true;
    });
    count.textContent = shown.length + t.count;

    table.textContent = '';
    var head = el('tr');
    [t.task, t.type, t.due].forEach(function (h) { head.appendChild(el('th', h)); });
    table.appendChild(head);
    if (!shown.length) {
      var empty = el('tr'); var cell = el('td', t.none, 'muted'); cell.colSpan = 3; empty.appendChild(cell); table.appendChild(empty);
    }
    shown.forEach(function (task) {
      var row = el('tr');
      var link = el('a', '#' + task.ID + ' ' + task.work_desc, 'go');
      link.addEventListener('click', function () { rc.ui.navigate('/edit_workflow?workid=' + task.ID); });
      var first = el('td'); first.appendChild(link);
      row.appendChild(first);
      row.appendChild(el('td', task.type));
      var late = task.due && task.due < now;
      row.appendChild(el('td', task.due ? task.due + (late ? ' (' + t.overdue + ')' : '') : '-', late ? 'late' : ''));
      table.appendChild(row);
    });
  }

  function load() {
    // done=0: only open tasks. assigned_worker: only mine. limit: how many at most (the API allows up to 200 per call).
    var url = '/tasks?done=0&assigned_worker=' + encodeURIComponent(ctx.user.username) + '&limit=200';
    rc.api.get(url).then(function (list) {
      list.sort(function (a, b) { return (a.due || '9999-99-99') < (b.due || '9999-99-99') ? -1 : 1; });   // no due date: last
      tasks = list;
      draw();
    }, function (err) {
      root.appendChild(el('p', explain(err), 'err'));
    });
  }

  rc.ready.then(function (ctx0) {
    ctx = ctx0;
    t = TEXT[ctx.user.lang] || TEXT.en;
    document.body.classList.toggle('dark', ctx.user.theme === 'dark');
    root = document.getElementById('root');
    root.appendChild(el('h2', t.title));

    var bar = el('div', '', 'bar');
    search = el('input'); search.type = 'text'; search.placeholder = t.search;
    lateBox = el('input'); lateBox.type = 'checkbox';
    var label = el('label'); label.appendChild(lateBox); label.appendChild(document.createTextNode(' ' + t.onlyLate));
    count = el('span', '', 'muted');
    [search, label, count].forEach(function (x) { bar.appendChild(x); });
    root.appendChild(bar);
    table = el('table'); root.appendChild(table);

    search.addEventListener('input', draw);
    lateBox.addEventListener('change', function () {
      prefs.onlyLate = lateBox.checked;
      rc.storage.set('user', 'prefs', prefs);   // remembered for this person; a failure here is not worth an error message
      draw();
    });

    // the remembered switch first, then the tasks; a missing document is null (not an error)
    rc.storage.get('user', 'prefs').then(function (p) {
      if (p) { prefs = p; lateBox.checked = !!p.onlyLate; }
    }, function () {}).then(load);
  });
})();
  1. The TEXT table. All words the page shows are in one place per language. ctx.user.lang is the language of the person (a German colleague sees German); TEXT[lang] || TEXT.en falls back to English for any other language.
  2. el() and today() are small helpers: one makes elements the safe way, the other gives today's date as YYYY-MM-DD. Because both the API and today() use that form, task.due < now compares dates correctly as plain text.
  3. load() asks for the tasks (up to 200), sorts them by due date (no date = last) and calls draw(). A failure (for example a missing right) is shown as a red line: never leave a failure silent, the person otherwise sees an empty page and nobody knows why.
  4. draw() builds the table from the tasks that pass the two filters. It runs again at every keystroke in the search box and every click on the switch. Clearing the table with table.textContent = '' and rebuilding it is the simplest thing that works, and fast enough for hundreds of rows.
  5. rc.ui.navigate('/edit_workflow?workid=...') takes the person to the task in the app. Only paths of the app are accepted.
  6. Remembering. rc.storage.set('user', 'prefs', prefs) stores a small JSON document for this person and this plugin; rc.storage.get('user', 'prefs') reads it back (null when nothing is stored yet - not an error). It needs the right storage:user. There are two more scopes: shared (everybody who uses the plugin) and object (on a task or project).

And the manifest of the final version (1.0.0), with the rights this code needs. Note optional_permissions: the card of the next section writes comments, but the radar page works without that right, so the plugin asks for it as optional; the administrator can decline it and everything else keeps working.

{
  "id": "io.resourcecloud.example.task-radar",
  "name": { "en": "Task Radar", "de": "Task-Radar" },
  "description": {
    "en": "The plugin of the tutorial: your open tasks sorted by due date with a search box and an 'only overdue' switch the plugin remembers, plus a card on every task with an 'I am on it' button.",
    "de": "Das Plugin des Tutorials: Ihre offenen Tasks nach Fälligkeit sortiert, mit Suchfeld und einem Schalter 'nur überfällige', den sich das Plugin merkt, dazu eine Karte an jedem Task mit einem Knopf 'Ich bin dran'."
  },
  "version": "1.0.0",
  "type": "ui",
  "author": { "name": "Resourcecloud example plugin" },
  "permissions": ["tasks:read", "storage:user"],
  "optional_permissions": ["tasks:comment"],
  "slots": [
    { "slot": "menu.page", "entry": "radar.html", "label": { "en": "Task Radar", "de": "Task-Radar" } },
    { "slot": "task.card", "entry": "card.html", "label": { "en": "Task Radar", "de": "Task-Radar" } }
  ]
}

Pack and upload (version 1.0.0, Update and allow). The dialog lists Read tasks, Keep its own data for each person and, marked optional, Comment on tasks. Try the search box and the switch, reload the page: the switch is where you left it.

6. A card on every task

A second place: task.card puts a card into the task editor. The manifest of step 5 already lists it. The page card.html is the same as radar.html with card.js and the same stylesheet:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>Task Radar card</title>
  <link rel="stylesheet" href="radar.css">
</head>
<body>
  <div id="root"></div>
  <script src="_rc/sdk.js"></script>
  <script src="card.js"></script>
</body>
</html>

card.js:

/*
 * Task Radar - the card on a task. Needs the OPTIONAL right tasks:comment. If the administrator declined it, the button answers with
 * a clear message instead of failing silently.
 *
 *   ctx.object.id                     -> the task the card sits on
 *   rc.api.post('/comments', {...})   -> writes a comment under the person's name ("via plugin")
 */
(function () {
  'use strict';

  var TEXT = {
    en: { text: 'I am on it', button: 'Write a comment', done: 'Comment written.', noRight: 'This plugin was not allowed to write comments.', failed: 'Something went wrong: ' },
    de: { text: 'Ich bin dran', button: 'Kommentar schreiben', done: 'Kommentar geschrieben.', noRight: 'Dieses Plugin darf keine Kommentare schreiben.', failed: 'Es ist etwas schiefgegangen: ' }
  };

  rc.ready.then(function (ctx) {
    var t = TEXT[ctx.user.lang] || TEXT.en;
    document.body.classList.toggle('dark', ctx.user.theme === 'dark');
    var root = document.getElementById('root');

    var button = document.createElement('button');
    button.textContent = t.button + ': "' + t.text + '"';
    var message = document.createElement('p');
    message.className = 'muted';
    root.appendChild(button);
    root.appendChild(message);

    button.addEventListener('click', function () {
      button.disabled = true;
      // minutes_used: 0 - without it the API books 10 minutes of work for the comment
      rc.api.post('/comments', { work_id: ctx.object.id, comment: t.text, minutes_used: 0 }).then(function () {
        message.className = 'muted';
        message.textContent = t.done;
      }, function (err) {
        message.className = 'err';
        message.textContent = err.code === 'plugin_permission' ? t.noRight : t.failed + err.message;
      }).then(function () { button.disabled = false; rc.ui.autoResize(); });
    });

    rc.ui.autoResize();   // a card is as high as its content
  });
})();

Open any task: the card Task Radar sits in the editor. Click the button and look at the task's comments.

7. Look and feel

The stylesheet radar.css is plain CSS. The listing:

body { margin: 0; padding: 14px; font: 14px/1.45 -apple-system, "Segoe UI", Roboto, sans-serif; color: #222; background: transparent; }
body.dark { color: #e6e6e6; }
h2 { margin: 0 0 10px; font-size: 20px; }
table { border-collapse: collapse; width: 100%; margin-top: 10px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: #777; padding: 4px 10px 4px 0; border-bottom: 1px solid #ccc; }
td { padding: 6px 10px 6px 0; border-bottom: 1px solid rgba(128, 128, 128, .25); vertical-align: top; }
a.go { color: #2a6ebb; cursor: pointer; text-decoration: underline; }
body.dark a.go { color: #7ab4f5; }
input[type=text], textarea { font: inherit; padding: 5px 8px; border: 1px solid #bbb; border-radius: 4px; box-sizing: border-box; }
button { font: inherit; padding: 5px 14px; border: 1px solid #2a6ebb; background: #2a6ebb; color: #fff; border-radius: 4px; cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
.bar { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.muted { color: #777; font-size: 12px; }
.late { color: #c62828; font-weight: 600; }
.err { color: #b00020; font-weight: 600; }

8. Change it and update

When something does not work

Press F12 on the page that shows your plugin. The plugin runs in a frame: in the console, switch the context selector (it says top) to your frame to type commands there, and watch the Console and Network tabs. console.log(x) in your code shows up there.

You seeLikely cause
Upload: "manifest ... is not valid", with a field namea typo or a missing comma in rcplugin.json. Paste it into a JSON checker. The pack tool says the line.
Upload: the page x.html of menu.page is not in the packagethe entry must be the path of a file in the package; check upper and lower case
Upload: "rcplugin.json not found"the manifest is inside a folder in the zip. Zip the files, not the folder (unzip -l shows it)
Upload: this kind of file is not allowedonly static files: html, js, css, json, images, fonts, wasm, txt, md. No PHP, no .sh
Upload: the folder _rc is reserveddo not ship the SDK; load _rc/sdk.js
The frame stays empty, console: rc is not definedthe <script src="_rc/sdk.js"> line is missing, has a leading slash, or comes after your own script
Console: Unexpected token / ... is not a functiona typo in your own JavaScript: the error names the file and line. A missing ) or } is the usual one
A 404 for one of your filesthe path is wrong: files are found relative to the page that loads them. radar.css next to radar.html works, /radar.css does not
"Refused to connect / load ... Content Security Policy"the page tries to reach a server outside its package. Your own files are fine. A server you really need goes into "network": ["https://host"] in the manifest (the administrator sees it in the dialog)
403, code: plugin_permissionthe right named in err.permission is missing: add it to the manifest, raise the version, upload, allow
403, plugin_blockedthat part of the API is never open to plugins (customers, billing, time booking, chats, ...). See the cookbook
404 on a call that should workthe thing does not exist or the person may not see it; the answer never says which
429too many calls: at most 120 per minute and plugin. Ask for a list once instead of one call per row
413, plugin_too_big / plugin_quotaone stored document may be 1 MB, everything of one plugin 100 MB
A sandbox message about cookies, localStorage or the parent pagea plugin has none of these. Keep data with rc.storage
The plugin is gone from the menuit is switched off, or a module it needs (requires_modules) is off
The list is empty but the person has tasksthe filters: assigned_worker must be a user name (ctx.user.username), not the full name

Do not use alert or confirm (the sandbox blocks them): rc.ui.toast('text', 'success') and rc.ui.confirm('text') do the same inside the app.

Share it inside your company

php tools/plugin_sign.php keygen my-company
php tools/plugin_sign.php index ./packages --key my-company.key --base-url https://plugins.my-company.example/files/ --out index.json
# on the instance (config or environment):
#   plugin_catalog="https://plugins.my-company.example/index.json"   plugin_catalog_keys="my-company:<public key line from keygen>"

When you need a server

If the plugin has to talk to a system only your server can reach, or needs a secret, make it a remote plugin: a page of your own server shown in the app. The manifest has no entry, only the address:

{ "id": "com.mycompany.cloud", "name": "Our cloud", "version": "0.1.0", "type": "remote",
  "remote": { "url": "https://cloud.mycompany.example/rc/" },
  "slots": [ { "slot": "menu.page", "label": "Our cloud" } ] }

Your server learns who is looking by trading a signed token and the plugin's secret for an API token, and calls the API as that person. The one-file demo server examples/plugins/remote-demo/server/index.php shows it; the guide's section 7 explains it.

Checklist before you roll it out

Where to look next