logologo
Get Started
Tutorials
Guide
Development
Plugins
API
Home
English
简体中文
日本語
한국어
Español
Português
Deutsch
Français
Русский
Get Started
Tutorials
Guide
Development
Plugins
API
Home
logologo
RunJS Overview
Importing Modules
Rendering in Container

Global Variables

window
document
navigator

ctx

ctx.blockModel
ctx.collection
ctx.collectionField
ctx.dataSource
ctx.dataSourceManager
ctx.element
ctx.exit()
ctx.exitAll()
ctx.filterManager
ctx.form
ctx.getModel()
ctx.getValue()
ctx.getVar()
ctx.i18n
ctx.importAsync()
ctx.initResource()
ctx.libs
ctx.location
ctx.logger
ctx.makeResource()
ctx.message
ctx.modal
ctx.model
ctx.notification
ctx.off()
ctx.on()
ctx.openView()
ctx.render()
ctx.request()
ctx.requireAsync()
ctx.resource
ctx.route
ctx.router
ctx.setValue()
ctx.sql
ctx.t()
ctx.view
Previous Pagectx.element
Next Pagectx.exitAll()

#ctx.exit()

Terminates the execution of the current event flow; subsequent steps will not run. It is commonly used when business conditions are not met, the user cancels, or an irrecoverable error occurs.

#Use Cases

ctx.exit() is generally used in the following contexts where JS can be executed:

ScenarioDescription
Event FlowIn event flows triggered by form submissions, button clicks, etc., terminates subsequent steps when conditions are not met.
Linkage RulesIn field linkages, filter linkages, etc., terminates the current event flow when validation fails or execution needs to be skipped.
Action EventsIn custom actions (e.g., delete confirmation, pre-save validation), exits when the user cancels or validation fails.

Difference from ctx.exitAll(): ctx.exit() only terminates the current event flow; other event flows under the same event are not affected. ctx.exitAll() terminates the current event flow as well as any subsequent event flows under the same event that have not yet been executed.

#Type Definition

exit(): never;

Calling ctx.exit() throws an internal FlowExitException, which is caught by the FlowEngine to stop the current event flow execution. Once called, the remaining statements in the current JS code will not execute.

#Comparison with ctx.exitAll()

MethodScope of Effect
ctx.exit()Terminates only the current event flow; subsequent event flows are unaffected.
ctx.exitAll()Terminates the current event flow and aborts subsequent event flows under the same event that are set to execute sequentially.

#Examples

#Exit on User Cancellation

// In a confirmation modal, terminate the event flow if the user clicks cancel
if (!confirmed) {
  ctx.message.info('Operation cancelled');
  ctx.exit();
}

#Exit on Parameter Validation Failure

// Prompt and terminate when validation fails
if (!params.value || params.value.length < 3) {
  ctx.message.error('Invalid parameters, length must be at least 3');
  ctx.exit();
}

#Exit When Business Conditions Are Not Met

// Terminate if conditions are not met; subsequent steps will not execute
const record = ctx.model?.getValue?.();
if (!record || record.status !== 'draft') {
  ctx.notification.warning({ message: 'Only drafts can be submitted' });
  ctx.exit();
}

#Choosing Between ctx.exit() and ctx.exitAll()

// Only the current event flow needs to exit → Use ctx.exit()
if (!params.valid) {
  ctx.message.error('Invalid parameters');
  ctx.exit();  // Other event flows are unaffected
}

// Need to terminate all subsequent event flows under the current event → Use ctx.exitAll()
if (!ctx.model?.context?.getPermission?.()) {
  ctx.notification.warning({ message: 'Insufficient permissions' });
  ctx.exitAll();  // Both the current event flow and subsequent event flows under the same event are terminated
}

#Exit Based on User Choice After Modal Confirmation

const ok = await ctx.modal?.confirm?.({
  title: 'Confirm Delete',
  content: 'This action cannot be undone. Do you want to continue?',
});
if (!ok) {
  ctx.message.info('Cancelled');
  ctx.exit();
}

#Notes

  • After calling ctx.exit(), subsequent code in the current JS will not execute; it is recommended to explain the reason to the user via ctx.message, ctx.notification, or a modal before calling it.
  • There is usually no need to catch FlowExitException in business code; let the FlowEngine handle it.
  • If you need to terminate all subsequent event flows under the current event, use ctx.exitAll().

#Related

  • ctx.exitAll(): Terminates the current event flow and subsequent event flows under the same event.
  • ctx.message: Message prompts.
  • ctx.modal: Confirmation modals.