Skip to content

Commit f9d1740

Browse files
authored
Merge pull request #353 from nocodb/docs/1018-webhook-run-script
docs: run scripts
2 parents 35d7d80 + 3209a49 commit f9d1740

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

content/docs/automation/webhook/create-webhook.mdx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,36 @@ Webhooks in NocoDB can be configured based on the source of the trigger and the
8383

8484
For more details on using **Button Trigger** webhooks with the **Button** field, see the [Button field documentation](/docs/product-docs/fields/field-types/custom-types/button).
8585

86+
---
87+
### Run Script action ☁
88+
89+
<Callout type="note">This feature is only available in the paid plans, in both cloud & self-hosted.</Callout>
90+
91+
The **Run Script** action enables you to execute custom JavaScript code directly within NocoDB whenever a webhook is triggered. It is ideal for use cases where data needs to be processed or transformed internally. When triggered, the associated script runs within NocoDB’s secure scripting engine and automatically receives an `event` object (see example below) containing the webhook context, such as record creation, update, or deletion details.
92+
93+
```javascript
94+
/*
95+
Update record on trigger; This script updates the 'Department' and 'Employment Status' fields when a new record is inserted. Note the usage of `cursor.row` to access the record that triggered the webhook.
96+
*/
97+
98+
const record = cursor.row;
99+
100+
// Exit if no record found (safeguard)
101+
if(!record) {
102+
return
103+
}
104+
105+
// Get the table
106+
const table1 = base.getTable("Employee")
107+
108+
// Update the record
109+
await table1.updateRecordAsync(record.id, {
110+
"Department": "New Hire",
111+
"Employment Status": "Active"
112+
})
113+
```
114+
115+
Refer to the [Scripts documentation](/docs/scripts#getting-started) for detailed guide on creating and managing scripts. Note that, scripts that seek explicit user input (such as `input.textAsync()`) cannot be used in webhook context, since webhooks run in the background without user interaction.
86116

87117
### Webhook with conditions
88118

0 commit comments

Comments
 (0)