Scripting Engine

Essembi's scripting engine is powered by JavaScript and is ECMAScript 6 (Strict). Within the areas that have scripting enabled, users can write JavaScript in a monaco-editor with auto-complete for the full ES6 standard library plus the Essembi library.

Where is the scripting engine available?

View Drill Downs

Drill downs can be configured for individual elements within chart views or from columns in sheet views. Examples of drill downs from chart views include:

  • Drill down from individual bar graph elements
  • Drill down from line graph results
  • Drill down from metric cards

Examples from sheet views include:

  • Drill down from a record into a form
  • Drill down from a high level summary into a lower level summary (e.g., formula level OEE drill down into work order level OEE results)

Form Buttons

A button with a custom click event can be added to any form. For example, the default work order form in Essembi contains buttons to simplify the operator inputs for starting, pausing, or finishing a work order. Typically these buttons are used to:

  • Creating or updating existing records or sub-records
  • Automatically navigate to other views or forms after an action is taken
  • Prompt the user to add more information via a custom prompt with an input field

Calculated Field Types

Calculated fields can be added to any table within Essembi. They can utilize logic that references other fields in tables within the organization's app. Because they are a field, they can be shown in views and/or data entry forms.

Calculated fields can be retrieved via API but cannot be set via API or any other method for security purposes.

Validations Script

Validation scripts enable Essembi users to throw a string to alert a user of a validation error when saving a record. It fires on the save of a form. Validation scripts also fires on data entered via alternative add methods such as API or entry via an Excel import to ensure data integrity.

JavaScript Library

The entirety of the Javascript standard library has been exposed, excluding any aspects of the library that would interact with the Document Object Model (DOM), Window, or other client-specific functions and objects. This means you can use objects like "Math" and "JSON" but not "window" or "document."

For help on coding with JavaScript ES6, check out this guide from Programiz.

Essembi's Library

Record Object Schema

A record is any instance of any data that has been saved in a table in Essembi. The following methods and properties are available on all records.

Function / Property Description Parameters Returns
getValue(fieldName: string): any Returns the value of the specified field. fieldName (string): The name of the field. any
getReferenceValue(referenceFieldName: string): Record Returns a reference to the record populated in the specified reference field. referenceFieldName (string): The name of the reference field. Record
setValue(fieldName: string, value: any): void Sets the value of the specified field. fieldName (string): The name of the field.
value (any): The value to set.
void
getSubRecords(tableName: string, includeArchived?: boolean): Record[] Returns an array of sub-records from the specified table. tableName (string): The name of the table to get sub-records from.
includeArchived (boolean, optional): If true, include archived records in the result. Defaults to false.
Record[]
createSubRecord(tableName: string): Record Returns a new sub-record for the specified table. tableName (string): The name of the table. Record
id: number The ID of the record. None number
created: Date The created time of the record in UTC. None Date
name: string The name of the record, if a "use as record's name" short text field is defined. None string
sort: number Gets or sets the sort of the record, if a "use as record's sort" integer field is defined. None number
color: number The color of the record, if a "use as record's color" color field is defined. None number
icon: string The icon of the record, if a "use as record's icon" short text field is defined. None string
archived: boolean Gets or sets whether the record is archived. None boolean

Drill Downs and View Navigation

Drill down scripts allow you to navigate from one view to another with contextual filtering. These are commonly used in charts, metric cards, and sheets to provide deeper analysis when users click on data points.

Loading Views

The app object provides methods to load different view types. All methods support optional filtering to show relevant data.

Method Description Parameters Returns
loadSheetView() Loads a sheet (grid) view workspaceName (string): The workspace name
viewName (string): The view name
savedFilters (string, optional): Saved filter name
SheetView
loadChartsView() Loads a charts view workspaceName (string): The workspace name
viewName (string): The view name
displayOption (string, optional): Display option
ChartsView
loadBoardView() Loads a board (kanban) view workspaceName (string): The workspace name
viewName (string): The view name
savedFilters (string, optional): Saved filter name
BoardView
loadGanttView() Loads a gantt view workspaceName (string): The workspace name
viewName (string): The view name
savedFilters (string, optional): Saved filter name
GanttView

Adding Filters to Views

After loading a view, you can add dynamic filters using the addFilter() method. This is useful for showing only relevant records based on user interaction.

//-- Load the view
let view = app.loadSheetView('Sales', 'All Orders');

//-- Add a filter to show only orders for a specific customer
view.addFilter('Orders', 'Customer', 'Equal', customerId);

//-- Add a date range filter
view.addFilter('Orders', 'Order Date', 'Between', startDate, endDate);

return view;
Filter Conditions

Common filter conditions include:

  • Equal - Exact match
  • Not Equal - Does not match
  • Greater Than, Less Than - Numeric/date comparisons
  • Between - Range filter (requires endValue parameter)
  • Contains - Text contains substring
  • Is Empty, Is Not Empty - Null checks

Adding Options to Views

The addOption() method configures view-specific settings like grouping dimensions or time ranges.

//-- Load the charts view
let view = app.loadChartsView('Production', 'Metrics Dashboard');

//-- Set chart options
view.addOption('Dimension', 'Product Line');
view.addOption('Time Period', 'Last 30 Days');

return view;

Customizing View Names

You can set a custom name for the loaded view to provide context:

//-- Load the view and filter it
let view = app.loadSheetView('Incidents', 'All Incidents');
view.addFilter('Incidents', 'Status', 'Equal', 'Open');

//-- Set a custom name
view.name = "Open Incidents - Line 3";

return view;

Opening Forms from Scripts

You can also navigate to forms to create or edit records:

Method Description Parameters
createRecordInForm() Opens a form to create a new record formName (string): The form name
defaultValues (object, optional): Default field values
editRecordInForm() Opens a form to edit an existing record formName (string): The form name
recordId (number): The record ID to edit

Example Form Opened from Script


//-- Create a new work order with default values return app.createRecordInForm('Work Order', { 'Line': 'Production Line 1', 'Priority': 'High' }); //-- Edit an existing record const workOrderId = record.getValue('Work Order ID'); return app.editRecordInForm('Work Order', workOrderId);

Building Dynamic Inquiry Prompts

You can prompt users for input using the form.createInquiry() method. This displays a dialog where users can enter information before the script continues executing.

Basic Usage

//-- Create and show a prompt
const result = form.createInquiry('Dialog Title')
  .withInfo('Enter the required information:')
  .withShortTextField('fieldName', 'Field Label', { required: true })
  .show();

//-- Check if user canceled
if (!result) {
  return 'Action canceled';
}

//-- Access the user's input
const userInput = result.fieldName;

Available Dynamic Field Types

Method Description Parameters
withShortTextField() Adds a single-line text input field resultName (string): Name to access the result
caption (string): Field label
options (object, optional): Settings like required and default
withLinkedTableField() Adds a dropdown to select a record from another table resultName (string): Name to access the result
caption (string): Field label
table (string): The table name to link to
options (object, optional): Settings like required and default
withCheckBoxField() Adds a checkbox field resultName (string): Name to access the result
caption (string): Field label
options (object, optional): Settings like nullable and default
withDateField() Adds a date picker field resultName (string): Name to access the result
caption (string): Field label
options (object, optional): Settings like nullable, required, and default
withDateTimeField() Adds a date and time picker field resultName (string): Name to access the result
caption (string): Field label
options (object, optional): Settings like nullable, required, and default
withTimeField() Adds a time picker field resultName (string): Name to access the result
caption (string): Field label
options (object, optional): Settings like nullable, required, and default
withInfo() Adds informational text (not an input field) caption (string): The text to display

Handling Results

When the user submits the prompt, you receive an object with properties matching the resultName values you specified. If the user cancels, show() returns null.

const result = form.createInquiry('Select Options')
  .withShortTextField('name', 'Name', { required: true })
  .withDateField('date', 'Date')
  .show();

if (!result) {
  return 'User canceled';
}

//-- Access the values
const name = result.name;
const date = result.date;

Returning Messages

Button scripts can return a string that will be displayed to the user after execution:

return "Operation completed successfully!";

Current User Properties

The user object provides access to information about the currently logged-in user. This is useful for personalizing scripts, filtering data based on user identity, or logging user actions.

Property Description Returns
user.firstName The current user's first name string
user.lastName The current user's last name string
user.fullName The current user's first and last name string
user.email The current user's email address string

Example Scripts

Drill Downs

Drill Down from Sheet to Record in Form

Sample Drill Down into the Work Order Form

const workOrderRecord = record.getReferenceValue('Work Order');
const workOrderId = workOrderRecord.id;
const workOrderForm = app.editRecordInForm('Work Order', workOrderId);

return workOrderForm;

Drill Down from Bar Chart to View

Sample Drill Down from a the OEE Bar Chart to the OEE Details Sheet View

let endDate = new Date(axisValue);
endDate.setHours(endDate.getHours() + 4 - 1);

let view = app.loadSheetView('OEE', 'OEE (Last 24 Hours)');

view.addFilter('Work Order Routing', 'Line', 'Equal', 'Powder Line #1');
view.addOption('Dimension', 'Work Order');
view.addOption('End Time', endDate);
view.addOption('Number of Hours', 1)
view.name = `OEE Details`;

return view;

Drill Down from Metric Card to View

Sample Drill Down from an OEE Metric Card to the OEE Details Sheet View

let view = app.loadSheetView('OEE', 'OEE (Last 24 Hours)');

view.addFilter('Work Order Routing', 'Line', 'Equal', 'Powder Line #1');
view.addOption('Dimension', 'Work Order');
view.addOption('Number of Hours', 24);

view.name = "OEE Details";

return view;

Sample Drill Down from Downtime Metric Card to Incidents Detail View

let view = app.loadSheetView('Incidents', 'Incident Details');

view.addFilter('Work Order Routing', 'Line', 'Equal', 'Powder Line #1');
view.addFilter('Incident', 'Start', 120);

view.name = "Incident Details";

return view;

Drill Down to Chart View

Sample Drill Down into Another Chart View

let view = app.loadChartsView('OEE', 'Powders');

view.name = "OEE Breakdown";

return view;
Back to help