Execute Javascript Code And Stop Execution
Audience:
Low-code EngineersSkill Prerequisites:
Actions,JavaScript,Tokens
Runs JavaScript code in the user's browser and ends execution. No actions after it run. It's available in forms and listings.
The code is the response to the button or event, so it's the last thing that happens. Actions that ran before it aren't undone. In a form, the code can read and change fields through the form object, for example form.fields.TextBox.value.
Typical Use Cases
- Finish a button's actions with a client-side effect, such as opening a page in a new tab or printing
- Show a custom dialog or a browser
alertwith values from earlier actions, and stop there - Stop processing with a condition, and use the code to move the focus to the field that needs attention
Don't use it to
- Run code and then carry on with more actions. Use Execute Javascript Code And Continue Execution instead.
- Stop without running code. Use Stop Execution instead.
- Run code on the server. Use Execute JavaScript (Server-side) instead.
- Enforce security or business rules. The code runs in the browser, where users can see and change it.
Related Actions
| Action Name | Description |
|---|---|
| Execute Javascript Code And Continue Execution | Runs JavaScript in the browser and continues with the next actions. |
| Stop Execution | Ends execution without a response. |
| Execute JavaScript (Server-side) | Runs JavaScript on the server. |
| Display Message | Shows a message and ends execution, without writing code. |
Input Parameter Reference
| Parameter | Description | Supports Tokens | Default | Required |
|---|---|---|---|---|
| Javascript Code | The JavaScript to run in the browser. Tokens such as [FirstName] are replaced with their values on the server before the code is sent. In a form, fields are also available as form.fields.<FieldName>.value. | Yes | empty string | No |
How the code runs
- Tokens are replaced as plain text. Values aren't escaped for JavaScript. Put tokens inside quotes, for example
'[FirstName]'. A value that contains a quote or a line break breaks the code, so read user input fromform.fieldsinstead of tokens. - The
formobject is available in forms.form.fields.<FieldName>.valueholds the current value of a field. It isn't available in listings. - Errors are only logged. The code is wrapped in a
try/catch. If it throws, the error is written to the browser console, starting withExecute JsCode Action Error. Execution still ends.
Considerations
- Final action. Actions placed after it in the same list never run, unless its condition is false. Use the action's
Conditionto decide when to stop. See Common Parameters. - Scripting license. The action needs the
Standard.Scriptingfeature. If it isn't licensed, the action fails with an error. System pages skip this check. - Visible to users. Don't put passwords, keys or other secrets in the code or in the tokens it uses.
Examples
To understand how to use the below examples, please see Running Examples.
1. Open the generated invoice in a new tab
This action opens the invoice created by earlier actions in a new browser tab. The [InvoiceUrl] token is placed inside quotes. Nothing runs after it.
{
"Title": "Execute Javascript Code And Stop Execution",
"ActionType": "ExecuteJsCode",
"Description": "Show the invoice",
"Parameters": {
"JavascriptCode": "window.open('[InvoiceUrl]', '_blank');"
}
}
2. Stop and point the user to a missing value
This action only runs when the Phone field is empty. It shows an alert, moves the focus to the field with the id Phone, and stops the remaining actions.
{
"Title": "Execute Javascript Code And Stop Execution",
"ActionType": "ExecuteJsCode",
"Description": "Ask for a phone number",
"Condition": "[Phone] == \"\"",
"Parameters": {
"JavascriptCode": "alert('Please add a phone number so we can confirm your booking.');\nvar el = document.getElementById('Phone');\nif (el) { el.focus(); }"
}
}
Revised 09/26/2026