eLabSDK2.Journal.Experiment.Section.CustomSection
Registers custom experiment section types, and gives the add-on that owns a custom section its
content, facts, files and images.
The data methods (getContent to removeImage) are served by the host to the frames of the
add-on that owns the section: the sandboxed frame of a section body and the add-on's hidden
frame, so an importer running there reaches the sections it owns too. Each takes the section id
first. A call is refused with SECTION_SCOPE_REFUSED unless the calling add-on's root var is the
root var the section was created with, the section is in the experiment open on the page, and the
call comes from one of the add-on's frames (a script running on the page itself is refused). The
server then decides as for the user: a signed or archived experiment, another user's lock or a
missing permission is refused there, and the call rejects with the server's code.
create and getSections take the id of the experiment open on the page instead and act only
on the calling add-on's own types and sections, under the same frame rule; create is refused by
the host where the user could not add a section from the journal (see its documentation).
Every rejection is an Error with a string code, from the list in each method's
documentation; a typed refusal of the server passes through as its name, such as
CannotChangeSignedExperimentSectionError. The host shows the user no message for a refused
call: tell your user yourself.
A file dropped on the section body lands in your frame: read the File objects from the drop
event and pass each to attachFile or attachImage.
Hierarchy
-
↳
CustomSection
Methods
attachExternalFiles
Static attachExternalFiles(sectionId, files): Promise<void>
Have the host fetch files by URL and attach them to a custom section your add-on owns, with
the rules FileSection.attachExternalFile applies to a Files section: each URL must be a
cross-origin https URL, it is fetched without the user's cookies within the upload limit,
and the file goes through the upload the Files section uses. Resolves once the host has
started fetching them; the host tells the user when one cannot be fetched or stored, and
getFiles lists the files once they are stored.
Rejects with SECTION_SCOPE_REFUSED (see the class description), or INVALID_ARGUMENT for a
section id that is not a positive integer, an empty list, or an entry without a url and a
non-blank name, or with headers that are not strings.
Parameters
| Name | Type | Description |
|---|---|---|
sectionId | number | The id of the section. |
files | CustomSectionExternalFile[] | [{url: string, name: string, headers?: Record<string, string>}] |
Returns
Promise<void>
Example
await eLabSDK2.Journal.Experiment.ExperimentSection.CustomSection.attachExternalFiles(ctx.sectionId, [
{ url: 'https://files.example.com/run-42.csv', name: 'run-42.csv', headers: { Authorization: `Bearer ${token}` } },
]);attachFile
Static attachFile(sectionId, file): Promise<{ fileId: number }>
Attach a file to a custom section your add-on owns, through the upload the Files section
uses. The server's upload limit and file rules apply. Resolves with the new file's id.
Rejects with SECTION_SCOPE_REFUSED (see the class description), INVALID_ARGUMENT for a
section id that is not a positive integer, a blank name or data that is not a Blob,
the server's refusal as its name (FileTooLargeError, InvalidExperimentSectionFileNameError,
InvalidExperimentSectionFileTypeError, CannotChangeSignedExperimentSectionError,
CannotChangeArchivedExperimentSectionError, CannotChangeArchivedExperimentSectionSectionError,
InvalidExperimentSectionTypeError or InvalidExperimentSectionUserError), or
UPLOAD_FAILED when the server refuses it without a typed error (no permission, no network).
Parameters
| Name | Type | Description |
|---|---|---|
sectionId | number | The id of the section. |
file | CustomSectionAttachInput | {name: string, data: Blob} |
Returns
Promise<{ fileId: number }>
Example
const { fileId } = await eLabSDK2.Journal.Experiment.ExperimentSection.CustomSection.attachFile(ctx.sectionId, {
name: 'results.csv',
data: new Blob([csv], { type: 'text/csv' }),
});attachImage
Static attachImage(sectionId, image): Promise<{ fileId: number }>
Attach an image to a custom section your add-on owns, through the upload the Images section
uses: JPEG, PNG, GIF, WebP or TIFF, checked by its content. The server's upload limit
applies. Resolves with the new image's file id.
Rejects with SECTION_SCOPE_REFUSED (see the class description), INVALID_ARGUMENT for a
section id that is not a positive integer, a blank name or data that is not a Blob,
the server's refusal as its name (FileTooLargeError, InvalidExperimentSectionFileNameError,
InvalidExperimentSectionImageTypeError, InvalidExperimentSectionImageContentError,
CannotChangeSignedExperimentSectionError, CannotChangeArchivedExperimentSectionError,
CannotChangeArchivedExperimentSectionSectionError, InvalidExperimentSectionTypeError or
InvalidExperimentSectionUserError), or UPLOAD_FAILED when the server refuses it without a
typed error (no permission, no network).
Parameters
| Name | Type | Description |
|---|---|---|
sectionId | number | The id of the section. |
image | CustomSectionAttachInput | {name: string, data: Blob} |
Returns
Promise<{ fileId: number }>
Example
const { fileId } = await eLabSDK2.Journal.Experiment.ExperimentSection.CustomSection.attachImage(ctx.sectionId, {
name: 'plate.png',
data: await new Promise((resolve) => canvas.toBlob(resolve, 'image/png')),
});create
Static create(experimentId, section): Promise<number>
Add a section of one of your add-on's types to the experiment open on the page, as the user
adding it from the journal's add menu does: the add-on must be installed and active for the
user, and the experiment must not be archived and the user must be allowed to configure it,
as for the add menu (a signed experiment takes new sections, as it does from the add menu).
It needs no user gesture, so an importer in your add-on frame can call it; the journal shows
the new section in place and does not scroll to it. Resolves with the new section's id; give
it its first content with saveContent.
Rejects with SECTION_SCOPE_REFUSED when the experiment is not the one open on the page or
the call does not come from one of your add-on's frames, INVALID_ARGUMENT for an
experiment id that is not a positive integer, a blank typeId or name, a performedAt
that is not an ISO 8601 date or a date-time with Z or an offset, or an afterSectionId
that is not a section of the experiment, TYPE_NOT_REGISTERED when your add-on has not
registered typeId on the page, ADDON_NOT_AVAILABLE when your add-on is not installed and
active for the user, READ_FAILED when the add-ons installed for the user cannot be read,
EXPERIMENT_NOT_EDITABLE when the experiment is archived, has not loaded on the page yet or
the user may not configure it, the server's refusal as its name, a top-level error's code
such as AUTH_NOT_AUTHORIZED, or CREATE_FAILED when it could not be added for another reason. A
rejection after the request was sent can still follow an added section, so check
getSections before you try again.
Parameters
| Name | Type | Description |
|---|---|---|
experimentId | number | The id of the experiment open on the page: ctx.experimentId in a body, or await eLabSDK2.Journal.Experiment.ExperimentDetail.getExperimentId() in your add-on frame. |
section | CustomSectionCreateInput | {typeId: string, name: string, performedAt?: string, afterSectionId?: number} The fields are described at CustomSectionCreateInput. |
Returns
Promise<number>
The id of the new section.
Example
const sections = eLabSDK2.Journal.Experiment.ExperimentSection.CustomSection;
const sectionId = await sections.create(ctx.experimentId, {
typeId: 'plateReader',
name: 'Plate run 2',
afterSectionId: ctx.sectionId,
});
await sections.saveContent(sectionId, { html: '<p>No readings yet</p>' });getContent
Static getContent(sectionId): Promise<CustomSectionContent>
Read the stored content of a custom section your add-on owns. The host reads the
experiment's sections from the server first, so a save made elsewhere is included.
The host stores the HTML only, so state is always null. The server keeps no record of
whether a stored state still matches the HTML (for example after a restore from History),
so no isStale is returned; that name is reserved for when it does.
Rejects with SECTION_SCOPE_REFUSED (see the class description), INVALID_ARGUMENT for a
section id that is not a positive integer, or READ_FAILED when the sections cannot be read.
Parameters
| Name | Type | Description |
|---|---|---|
sectionId | number | The id of the section (ctx.sectionId in its body). |
Returns
Promise<CustomSectionContent>
{ html, state, savedAt }
Example
const { html, savedAt } = await eLabSDK2.Journal.Experiment.ExperimentSection.CustomSection.getContent(sectionId);getFile
Static getFile(sectionId, fileId): Promise<CustomSectionFileData>
Read the bytes of a file attached to a custom section your add-on owns. The host fetches
them with the user's session, which your frame does not have. Reading is not a download, so
no download is recorded in the section's audit trail.
Rejects with SECTION_SCOPE_REFUSED (see the class description), INVALID_ARGUMENT for
an id that is not a positive integer, NOT_FOUND when the file is not attached to the
section, AUTH_NOT_AUTHORIZED or LIST_FAILED when the files cannot be listed, or
DOWNLOAD_FAILED when the bytes cannot be read.
Parameters
| Name | Type | Description |
|---|---|---|
sectionId | number | The id of the section. |
fileId | number | The fileId from getFiles or attachFile. |
Returns
Promise<CustomSectionFileData>
{ blob, name, contentType }
Example
const { blob, name } = await eLabSDK2.Journal.Experiment.ExperimentSection.CustomSection.getFile(ctx.sectionId, fileId);
const text = await blob.text();getFiles
Static getFiles(sectionId): Promise<CustomSectionFile[]>
List the files attached to a custom section your add-on owns, by name. Removed files are
left out, and so are linked files, which are stored outside eLab. The list is complete:
the host reads every page of it.
Rejects with SECTION_SCOPE_REFUSED (see the class description), INVALID_ARGUMENT for a
section id that is not a positive integer, AUTH_NOT_AUTHORIZED when the user may not read
the section, or LIST_FAILED when the files cannot be listed.
Parameters
| Name | Type | Description |
|---|---|---|
sectionId | number | The id of the section. |
Returns
Promise<CustomSectionFile[]>
[{ fileId, name, updatedAt }]
Example
const files = await eLabSDK2.Journal.Experiment.ExperimentSection.CustomSection.getFiles(ctx.sectionId);getImage
Static getImage(sectionId, fileId): Promise<CustomSectionFileData>
Read the bytes of an image attached to a custom section your add-on owns.
Rejects with SECTION_SCOPE_REFUSED (see the class description), INVALID_ARGUMENT for
an id that is not a positive integer, NOT_FOUND when the image is not attached to the
section, AUTH_NOT_AUTHORIZED or LIST_FAILED when the images cannot be listed, or
DOWNLOAD_FAILED when the bytes cannot be read.
Parameters
| Name | Type | Description |
|---|---|---|
sectionId | number | The id of the section. |
fileId | number | The fileId from getImages or attachImage. |
Returns
Promise<CustomSectionFileData>
{ blob, name, contentType }
Example
const { blob } = await eLabSDK2.Journal.Experiment.ExperimentSection.CustomSection.getImage(ctx.sectionId, fileId);
image.src = URL.createObjectURL(blob);getImages
Static getImages(sectionId): Promise<CustomSectionImage[]>
List the images attached to a custom section your add-on owns, in their order. Removed
images are left out. The list is complete: the host reads every page of it.
Rejects with SECTION_SCOPE_REFUSED (see the class description), INVALID_ARGUMENT for a
section id that is not a positive integer, AUTH_NOT_AUTHORIZED when the user may not read
the section, or LIST_FAILED when the images cannot be listed.
Parameters
| Name | Type | Description |
|---|---|---|
sectionId | number | The id of the section. |
Returns
Promise<CustomSectionImage[]>
[{ fileId, name, updatedAt, caption, position }]
Example
const images = await eLabSDK2.Journal.Experiment.ExperimentSection.CustomSection.getImages(ctx.sectionId);getSection
Static getSection(sectionId): Promise<CustomSectionFacts>
Read the facts of a custom section your add-on owns: its name, when the work was performed,
who created and last changed it and when, whether the experiment is archived, who holds the
section's lock, and the add-on version recorded when the section was created. The host reads
the experiment's sections from the server first.
Rejects with SECTION_SCOPE_REFUSED (see the class description), INVALID_ARGUMENT for a
section id that is not a positive integer, or READ_FAILED when the sections cannot be read.
Parameters
| Name | Type | Description |
|---|---|---|
sectionId | number | The id of the section. |
Returns
Promise<CustomSectionFacts>
Example
const facts = await eLabSDK2.Journal.Experiment.ExperimentSection.CustomSection.getSection(ctx.sectionId);
if (facts.lock) console.log(`${facts.lock.user.firstName} is editing it`);getSections
Static getSections(experimentId, options?): Promise<CustomSectionFacts[]>
List the sections your add-on owns in the experiment open on the page, in journal order,
with the facts getSection returns for each. The host reads the experiment's sections from
the server first, so a section another user added is included. Sections of other add-ons are
never listed. The journal reads at most 100 sections of an experiment at once, so the list
would be cut short past that; then it rejects instead.
Rejects with SECTION_SCOPE_REFUSED when the experiment is not the one open on the page or
the call does not come from one of your add-on's frames, INVALID_ARGUMENT for an experiment
id that is not a positive integer or a typeId that is not a non-blank string,
TOO_MANY_SECTIONS when the experiment has 100 sections or more, a top-level error's code
such as AUTH_NOT_AUTHORIZED, or READ_FAILED when the sections cannot be read.
Parameters
| Name | Type | Description |
|---|---|---|
experimentId | number | The id of the experiment open on the page. |
options? | CustomSectionQuery | {typeId?: string} |
Returns
Promise<CustomSectionFacts[]>
Example
const runs = await eLabSDK2.Journal.Experiment.ExperimentSection.CustomSection.getSections(ctx.experimentId, {
typeId: 'plateReader',
});registerType
Static registerType(registration): void
Register a custom experiment section type provided by your add-on.
Call it from your add-on's init itself. Registering tells the host that your add-on
provides the type; it makes no request, and whether the type is offered to a user is the
server's answer for the installed, active add-on. Registering the same rootVar and
typeId again replaces the earlier registration.
The registration is a plain object, so the same call works wherever your script runs.
The second argument of init tells you where that is: context.host is addon-frame in
the hidden add-on frame, section-frame in the frame of a custom section body, which runs
your script again to render that body, and absent anywhere else. Read it as context?.host.
In a section frame, while init runs, registerType registers the type for that frame
only. A section frame may not otherwise register or remove a type, or dispatch to the store:
the promise rejects with the code SECTION_CHANNEL_NO_REGISTRATION. Whatever else a section
body registers stays on the page after the section closes, with callbacks that no longer answer
(see CustomSectionBodyContext), so register page-level actions, notices and handlers when
context.host is not section-frame, and do not await them before registerType.
The host keeps the type's data (label, icon, the actions' data, the empty state and the
extra histories); the functions never leave the frame your script runs in.
The registration is refused, with a console warning and nothing registered, when
rootVar, typeId or label is missing or blank. In an add-on frame it is also refused
when rootVar is not the root var of the add-on making the call. An action without a
non-blank id and label is left out, and an unknown visibleWhen shows the action always;
the other fallbacks, with a console warning each (an unknown placement, a menu action's
visibleWhen, an emptyState without text), are described at CustomSectionAction and
CustomSectionTypeRegistration.
icon, the actions' icon and the empty state's icon are classes from the "Supported Font Awesome icons" list of
this documentation, written as listed there: fas fa-<name> for a solid icon (such as
'fas fa-dna') and fab fa-<name> for a brand icon (such as 'fab fa-slack'). For a class
outside that list the call logs one console warning naming it, and the host shows a question
mark in its place.
Parameters
| Name | Type | Description |
|---|---|---|
registration | CustomSectionTypeRegistration | {rootVar: string, typeId: string, label: string, icon?: string, actions?: CustomSectionAction[], emptyState?: CustomSectionEmptyState, history?: CustomSectionHistoryView[], onMountBody: (ctx: CustomSectionBodyContext) => void | string | Promise<void | string>, onUnmountBody?: (ctx: CustomSectionBodyContext) => void, serialize: (ctx: CustomSectionBodyContext) => CustomSectionSerialized | Promise<CustomSectionSerialized>, onReadOnlyChange?: (readOnly: boolean) => void} |
Returns
void
Example
var myAddon = {
init: function (config, context) {
eLabSDK2.Journal.Experiment.ExperimentSection.CustomSection.registerType({
rootVar: 'myAddon',
typeId: 'plateReader',
label: 'Plate reader',
icon: 'fas fa-flask',
actions: [
{
id: 'plateReaderRefresh',
label: 'Refresh readings',
icon: 'fas fa-download',
visibleWhen: 'editing',
onClick: (ctx) => refreshReadings(ctx),
},
{
id: 'plateReaderExport',
label: 'Export readings',
placement: 'menu',
onClick: (ctx) => exportReadings(ctx),
},
],
onMountBody: (ctx) => {
// The body runs in a sandboxed frame of its own, which runs no script from the markup.
ctx.contentRoot.innerHTML = ctx.savedHtml;
},
serialize: (ctx) => ({ html: ctx.contentRoot.innerHTML }),
});
},
};removeFile
Static removeFile(sectionId, fileId): Promise<void>
Remove a file from a custom section your add-on owns, as the Files section's Remove does:
the file stays in the section's history.
Rejects with SECTION_SCOPE_REFUSED (see the class description), INVALID_ARGUMENT for
an id that is not a positive integer, NOT_FOUND when the file is not attached to the
section, LIST_FAILED when the files cannot be listed, the server's refusal as its name
(CannotChangeSignedExperimentSectionError, CannotChangeArchivedExperimentSectionError,
CannotChangeArchivedExperimentSectionSectionError, InvalidExperimentSectionTypeError or
InvalidExperimentSectionUserError), AUTH_NOT_AUTHORIZED when the user may not change the
section, or REMOVE_FAILED when it could not be removed for another reason.
Parameters
| Name | Type | Description |
|---|---|---|
sectionId | number | The id of the section. |
fileId | number | The fileId from getFiles or attachFile. |
Returns
Promise<void>
Example
await eLabSDK2.Journal.Experiment.ExperimentSection.CustomSection.removeFile(ctx.sectionId, fileId);removeImage
Static removeImage(sectionId, fileId): Promise<void>
Remove an image from a custom section your add-on owns, as the Images section's Remove
does: the image stays in the section's history.
Rejects with the codes removeFile rejects with, NOT_FOUND meaning the image is not
attached to the section.
Parameters
| Name | Type | Description |
|---|---|---|
sectionId | number | The id of the section. |
fileId | number | The fileId from getImages or attachImage. |
Returns
Promise<void>
Example
await eLabSDK2.Journal.Experiment.ExperimentSection.CustomSection.removeImage(ctx.sectionId, fileId);saveContent
Static saveContent(sectionId, content): Promise<void>
Store content in a custom section your add-on owns, as the user's Save and ctx.save do:
the server writes a revision when the content changed, and when the user is editing the
section on this page the edit ends and the lock is released. state is accepted and not
stored yet. Use it from an importer in your add-on frame; in the body, ctx.save does the same.
Rejects with SECTION_SCOPE_REFUSED (see the class description), INVALID_ARGUMENT for a
section id that is not a positive integer, INVALID_SAVE when html is not a string,
SAVE_BUSY while another save of the section runs on this page, the server's refusal as
its name with the reason as the message (ExperimentSectionLockedError while another user
edits the section, CannotChangeSignedExperimentSectionError,
CannotChangeArchivedExperimentSectionError, CannotChangeArchivedExperimentSectionSectionError,
InvalidExperimentSectionTextTooLargeError, InvalidExperimentSectionTypeError or
InvalidExperimentSectionUserError), AUTH_NOT_AUTHORIZED when the user may not change the
section, or SAVE_FAILED when it could not be stored for another reason. The host shows the
user no message for a refusal; a save that ends the user's edit on this page confirms it as
the user's Save does.
Parameters
| Name | Type | Description |
|---|---|---|
sectionId | number | The id of the section. |
content | CustomSectionSerialized | {html: string, state?: unknown} |
Returns
Promise<void>
Resolves when the content is stored.
Example
await eLabSDK2.Journal.Experiment.ExperimentSection.CustomSection.saveContent(sectionId, {
html: '<table>…</table>',
});unregisterType
Static unregisterType(rootVar, typeId): void
Remove a custom section type registered with registerType. In an add-on frame the call
is refused, with a console warning, when rootVar is not the root var of the add-on making it.
Parameters
| Name | Type | Description |
|---|---|---|
rootVar | string | The rootVar used at registration. |
typeId | string | The typeId used at registration. |
Returns
void
Example
eLabSDK2.Journal.Experiment.ExperimentSection.CustomSection.unregisterType('myAddon', 'plateReader');© 2026 eLabNext
Updated about 12 hours ago