Run JavaScript on forms and lists
Section titled “Run JavaScript on forms and lists”This how-to is for builders who need a small piece of browser behaviour that
no setting offers — a warning when a late record opens, a class added to a list
so your CSS can style it, a log line while you test. You will learn where to write
an entity or view script, when each script runs, exactly what a script can read,
and a set of recipes you can copy. Scripts are available Since 1.8.
You need:
- Permission to edit the entity (for an entity script) or the view (for a view script). See Data Views & Faces for views and Create and design an entity for entities.
- Some JavaScript. A script is plain JavaScript; there is nothing to install.
Where to write a script
Section titled “Where to write a script”You can write a script on the entity, on a view, or on both.
| Write it on | When to use it | Where |
|---|---|---|
| The entity | The behaviour belongs to the records themselves, wherever they are opened. | Administration › Applications › Data Entities, select the entity, then the Web settings tab. |
| A view | The behaviour belongs to one way of presenting the records. | Open the view from the entity’s Views tab, then its Web settings tab. |
Write an entity script
Section titled “Write an entity script”- Open Administration › Applications › Data Entities and select the entity.
- Select the Web settings tab. It shows Initialization Scripts, with one code editor per face.
- Type your script into the editor of the face it should run on — for example View Entry.
- Select Save.
The Web settings tab appears only when you may edit the entity and the entity is not archived.
Write a view script
Section titled “Write a view script”- Open the entity, select the Views tab and open the view.
- Select the Web settings tab. Under the custom styles you will find Initialization Scripts.
- Type your script into the editor of the face it should run on.
- Save the view.
A view shows an editor only for the faces it actually uses: Create Entry and Update Entry when Editing entries allows creating or editing, View Entry when the record’s details are on, and one editor per list face you have switched on. A Proxy View has no Web settings tab.
When a script runs
Section titled “When a script runs”Each editor belongs to one face. The script runs once when that screen opens.
| Editor | Runs when | context.entry |
|---|---|---|
| Create Entry | The create form opens. | null (the record does not exist yet) |
| Update Entry | The edit form opens. | The record being edited |
| View Entry | The record’s details open. | The record shown |
| Table View | The list is shown as a table. | null |
| Kanban View | The list is shown as a kanban board. | null |
| Calendar View | The list is shown as a calendar. | null |
| Timeline View | The list is shown as a timeline. | null |
| Tree View | The list is shown as a tree. | null |
| Badge View | The list is shown as cards (the Card view face). | null |
A list-face script runs when the list loads and again when someone switches to that face. It runs once for the whole list, not once per row or card, and it does not receive the listed records. The counter face has no script.
Order. When both have a script for the same face, the view’s script runs first, then the entity’s. If one of them fails, the other still runs.
Which scripts run where.
| Where the screen is opened | Scripts that run | context.view | context.get('el') |
|---|---|---|---|
| In Administration, from the entity itself | The entity’s only | null | null |
| Through a view (the view’s own page, or the record opened from it) | The view’s, then the entity’s | The view | null |
| A View widget on a page (list faces) | The view’s, then the entity’s | The view | The widget’s own element |
What a script can use
Section titled “What a script can use”A script receives one object, context. Use it for everything; inside a script,
window, document and console are not the browser’s — reach them through
context.get('w').
| Member | What it is | Available on |
|---|---|---|
context.entity | The entity: normalizedName, name ({ en, ar }), fields (each with normalizedName, name, dataType) and the rest of its design. | Every face |
context.view | The view: normalizedName, name ({ en, ar }) and the rest of its design. null when no view is involved. | Screens opened through a view |
context.entry | The record: id, value (the field values, keyed by each field’s normalized name), state, creationInfo and updateInfo (doneAt, doneBy). null on the create form and on list faces. | Update Entry, View Entry |
context.entries | An array of records. On a form or details screen it holds the one record, [entry]; on the create form and on list faces it is empty, []. It is never null. | Every face |
context.popupManager | The platform’s dialog service. Its one method, open(component, config), needs a platform screen component, which a script does not have. For a simple message use context.get('w').alert(...) instead. | Every face |
context.get('w') | The browser window. Use it for alert, confirm, setTimeout, console and document. Inside a View widget, context.get('w').document.querySelector, querySelectorAll and getElementById search only that widget. | Every face |
context.get('el') | The element of the View widget that ran the script, or null anywhere else. | List faces inside a View widget |
Good to know about values:
- A field’s value is in
context.entry.value.<normalized name>— for examplecontext.entry.value.due_date. A field the person may not see is missing fromvalue, so always allow forundefined. - A reference field holds an object with
dataEntityanddataEntry(the referenced entity and record ids), not a display text. - There is no form object: a script can read a record but cannot set field values or follow what someone types. See Things a script cannot do.
Cookbook
Section titled “Cookbook”Each recipe names the editor to put it in. Start every recipe by checking that what it needs is there.
See what the script receives
Section titled “See what the script receives”Put this in any editor while you build, open the screen and look in the browser’s developer console.
const w = context.get('w');w.console.log('[my-script]', { entity: context.entity?.normalizedName, view: context.view?.normalizedName ?? '(none)', entry: context.entry?.id ?? '(none)', values: context.entry?.value,});Warn when a late record opens
Section titled “Warn when a late record opens”View Entry. Shows a message when the record’s due date has passed.
const entry = context.entry;if (!entry) return;
const due = entry.value?.due_date; // your field's normalized nameif (!due) return; // empty or hidden: nothing to check
if (new Date(due) < new Date()) { context.get('w').alert('This request is past its due date.');}Use the field’s own label in a message
Section titled “Use the field’s own label in a message”View Entry or Update Entry. Reads the label from the entity, in the language the page is shown in.
const entry = context.entry;if (!entry) return;
const rtl = context.get('w').document.documentElement.dir === 'rtl';const lang = rtl ? 'ar' : 'en';const field = context.entity?.fields?.find((f) => f.normalizedName === 'priority');const label = field?.name?.[lang] ?? field?.name?.en ?? 'Priority';
if (!entry.value?.priority) { context.get('w').alert(`${label} is not set on this record yet.`);}Remind people of a rule when they start a new record
Section titled “Remind people of a rule when they start a new record”Create Entry on a view. There is no record yet, so use only entity and
view.
// Only for the portal view, not for every way of creating a record.if (context.view?.normalizedName !== 'asset_request_portal') return;
context.get('w').alert('Attach the signed approval form before you save.');Warn before editing an old record
Section titled “Warn before editing an old record”Update Entry.
const info = context.entry?.updateInfo ?? context.entry?.creationInfo;if (!info?.doneAt) return;
const days = (Date.now() - new Date(info.doneAt).getTime()) / 86400000;if (days > 30) { context.get('w').alert('This record has not changed for over a month. Check it is still current.');}Mark a list on a page so your CSS can style it
Section titled “Mark a list on a page so your CSS can style it”Table View (or any list face). Works inside a View widget on a page; the class goes on that widget only, even when the same view appears twice on the page.
const el = context.get('el');if (!el) return; // not inside a View widget
el.classList.add('urgent-list');Then style .urgent-list in the page or view CSS — see
Style a view with custom CSS.
Change one element inside the widget
Section titled “Change one element inside the widget”Table View, inside a View widget. getElementById searches only this
widget, so an id that repeats on the page still finds the right element.
if (!context.get('el')) return;
const doc = context.get('w').document;const banner = doc.getElementById('my-banner'); // an element your content providesif (banner) { banner.textContent = context.view?.name?.en ?? '';}Run the change only once
Section titled “Run the change only once”A list-face script can run more than once — for example when someone switches faces and back. Mark the element the first time.
const el = context.get('el');if (!el || el.dataset.myScriptDone) return;el.dataset.myScriptDone = 'yes';
el.classList.add('urgent-list');Wait for something to appear
Section titled “Wait for something to appear”If the element you need is not on screen yet when the script starts, try again a moment later.
const w = context.get('w');const el = context.get('el');if (!el) return;
w.setTimeout(() => { const rows = el.querySelectorAll('tr'); w.console.log('[my-script] rows on screen:', rows.length);}, 300);Things a script cannot do
Section titled “Things a script cannot do”| You want to | Use instead |
|---|---|
| Fill in a field when the form opens | A field’s starting value, or a button that pre-fills the form. |
| Compute a value from other fields | A calculated field or an expression. |
| React while someone types | Field validation and the form’s own rules. A script runs once, when the screen opens. |
| Count or total the records in a list | Totals and grouping or a summary. A list-face script does not receive the records. |
| Work on records people select | A script button with Multiple Entries. |
| Save or change data | A custom action button. A script only runs in the browser. |
Troubleshooting and good practice
Section titled “Troubleshooting and good practice”- Keep scripts small. One task per script. Long logic is hard to check and runs for everyone who opens the screen.
- Check before you use.
entry,viewandget('el')can benull, and a field may be missing fromentry.value. Use?.and return early. - Stay inside the widget. For DOM changes in a View widget, start from
context.get('el'), so two copies of the same view on one page do not affect each other. - Test on the real screen. The Preview panel in the view designer does not run scripts. Save, open the screen as a person would, and try each face you wrote a script for.
- Read the console. When a script fails, the error is written to the
browser’s developer console as
[EntityScript] error in view face "viewEntry"(orentity), with the view’s and entity’s normalized names. The screen keeps working. - Log with
context.get('w').console. Plainconsole.logdoes not work inside a script. - View script not running? Screens opened from the entity in Administration run only the entity’s script. Open the screen through the view to run the view’s script too.
See also
Section titled “See also”Platform 1.10.0 · Backend 1.11.0-alpha.11 · Frontend 1.11.0-alpha.6 · Mobile 1.10.2 · Chart 1.11.8 · Gateway 2.6.11 · MCP 0.2.0 · Grafana DS 1.2.0Docs build 2026-11-27