Execute Javascript Code
Audience:
Low-code EngineersSkill Prerequisites:
Actions,JavaScript,Listings,Tokens
Runs JavaScript code in the user's browser when a listing button is clicked, without a request to the server. It's a client-side action, so it's only available in listings, on buttons with Client Button turned on. See Listings Buttons.
A client button runs only client-side actions, one after another, as soon as it's clicked. You won't see this action anywhere else. On normal buttons, and in forms, use Execute Javascript Code And Stop Execution or Execute Javascript Code And Continue Execution instead.
| Action | Where you see it | When the code is prepared |
|---|---|---|
| Execute Javascript Code | Listing buttons with Client Button on | When the listing loads. Clicking the button only runs it. |
| Execute Javascript Code And Stop Execution | Forms, and normal listing buttons | When the button is clicked, on the server. |
| Execute Javascript Code And Continue Execution | Forms, and normal listing buttons | When the button is clicked, on the server. |
Typical Use Cases
- Open a page, a print dialog or a third-party widget from a listing button, instantly
- Copy a row's value to the clipboard, or show it in a browser dialog
- Call a JavaScript function that's already on the page, passing it values from the row
Don't use it to
- Run code as part of server actions, such as after saving data. Use Execute Javascript Code And Continue Execution on a normal button instead.
- Get values that change after the listing loads. Tokens are replaced when the listing loads, not when the button is clicked.
- 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 Stop Execution | Runs JavaScript in the browser from server actions, and ends execution. |
| Execute Javascript Code And Continue Execution | Runs JavaScript in the browser from server actions, and continues. |
| Initialize Form And Stop Execution | Also has a client-side version, Initialize Form, for client buttons. |
| Open Form Popup And Stop Execution | Also has a client-side version, Open Form Popup, for client buttons. |
| Refresh Listing | Reloads a listing on the page. |
Input Parameter Reference
| Parameter | Description | Supports Tokens | Default | Required |
|---|---|---|---|---|
| Javascript Code | The JavaScript to run in the browser. Tokens aren't replaced here. To use a token's value, add it to Parameters and read it as context.Params.<Name>. | No | empty string | No |
| Parameters | Name and value pairs passed to the code. Each value is available as context.Params.<Name>. Names are case sensitive. Tokens in both the names and the values are replaced when the listing loads. If a name is used twice, the last one wins. | Yes | empty | No |
How the code runs
- It's prepared when the listing loads. The server replaces the tokens in Parameters and sends the code to the browser with the listing. On an item button, this happens for each row, so row values, such as
[Id], are available. On a root button, only values that don't depend on a row are. - The condition is checked when the listing loads too. On an item button, it's checked for each row.
- Values are passed safely. Parameters are sent as JSON, so quotes and line breaks in a value don't break the code. That's why tokens go in Parameters, not in the code.
- What the code can use:
| Object | What it holds |
|---|---|
context.Params | The values from Parameters, by name. |
context.ModuleId | The ID of the listing module. |
settings | The listing's settings object. |
- There's no
formobject. The code runs in the listing, not in a form. - Errors are only logged. If the code throws, the error is written to the browser console. The next client actions on the button still run.
Considerations
- Mind how you show values. A value in
context.Paramscan be text a user typed. Use it withtextContentorinnerText, notinnerHTML, so it isn't run as HTML. - Visible to users. Don't put passwords, keys or other secrets in the code or the parameters. Anyone can see them in the page.
- Server actions are removed. When you turn on Client Button, the button's server-side actions are deleted when you save.
- Not in APIs, forms or workflows. This action is only for listing client buttons.
Examples
To understand how to use the below examples, please see Running Examples.
1. Open a row's details in a new tab
Add this action to an item button with Client Button on. It opens the order page for the row in a new tab. The row's Id is passed as a parameter, so it doesn't have to be placed in the code.
{
"Title": "Execute Javascript Code",
"ActionType": "ExecuteJavascriptClient",
"Description": "Open the order in a new tab",
"Parameters": {
"JavascriptCode": "window.open('/orders?id=' + encodeURIComponent(context.Params.OrderId), '_blank');",
"Params": [
{
"name": "OrderId",
"value": "[Id]"
}
]
}
}
2. Copy a row's email address
This action copies the row's Email value to the clipboard, but only on rows where Email isn't empty.
{
"Title": "Execute Javascript Code",
"ActionType": "ExecuteJavascriptClient",
"Description": "Copy the email address",
"Condition": "\"[Email]\" != \"\"",
"Parameters": {
"JavascriptCode": "navigator.clipboard.writeText(context.Params.Email);",
"Params": [
{
"name": "Email",
"value": "[Email]"
}
]
}
}
Revised 09/27/2026