Widget Code Structure
Widgets are implemented as anonymous classes that extend the HTMLElement class. The preferred approach is to extend SwimlaneElement, which itself extends LitElement and provides additional functionality for building rich, interactive record and report widgets in Turbine.
Widget Library and Examples
Swimlane publishes documentation and example code for its CDN-hosted widgets in the Swimlane Platform Custom Widgets library. Each widget page describes what the widget does and how to configure it. For example, see AI SOC Case Timeline. Use these pages as a reference when you customize a CDN-hosted widget.
Use a CDN-Hosted Widget
Swimlane hosts some widgets on a content delivery network (CDN), so you can add them to a layout without copying their source code. Paste an import statement into the widget editor, extend the imported class, and override settings in setConfig().
The version in the import URL controls which updates the widget receives:
- /index.js (no version) β You receive every new version automatically.
- /1/index.js β You receive new features and bug fixes within version 1.
- /1.0/index.js β You receive bug fixes only.
- /1.0.0/index.js β You receive no updates.
Each widget page in the Swimlane Platform Custom Widgets library describes the settings you can override.
Default Widget Example
Here is an example of the default widget with annotation added:
Properties
SwimlaneElement defines the following properties:
- this.record β Available to record widgets. An object containing key-value pairs for each field on the record.
- this.report β Available to report widgets. An object with:
- data: parsed result rows
- rawData: unprocessed backend response
- query: the report query
- this.contextData β Available to all widgets. Contains contextual information:
- application
- currentUser
- origin
- token
Documentation on how LitElement handles properties and attributes can be found here.
Lifecycle
In addition to standard HTMLElement and LitElement lifecycle methods, SwimlaneElement includes:
- resizedCallback() β Called when the widget is resized. By default, it calls requestUpdate() to trigger re-rendering.
Documentation of LitElement lifecycle methods and properties can be found here.
Events
Swimlane widgets can emit platform events using the following methods:
- this.updateRecordValue(key, value): Updates a specific record field by key.
- this.addComment(comment): Adds a comment to the record. This method returns a Promise, allowing follow-up actions to be chained: this.triggerButton(); }).catch(error => { console.error("Failed to add comment:", error); });
- this.triggerButton(buttonId): Triggers a playbook button by its ID.
- this.triggerSave(): Saves the current record. This method also returns a Promise, enabling safe sequencing of actions: this.triggerSave().then(() => { this.triggerButton(); }).catch(error => { console.error("Save failed:", error); });
Avoid using setTimeout() to delay follow-up actions. Use Promises to ensure actions happen after the save or comment completes successfully.
You can also perform multiple asynchronous actions in parallel using Promise.all():
Documentation on how to handle events in LitElement can be found here.
Value Emission Patterns
For single value fields (text/numeric/date fields, etc.) or single-select field types, simply emit the new value:
For text and numeric list field types, emit an array of new values. If duplicate values exist, their ids get reused:
For multi-select field types (selects, radio buttons, checkboxes), emit an array of new values. Every element in the value must exist in the contextData:
To add a comment, emit the new comment as a string: