Introduction
🌐 Webhooks are a powerful way to enable real-time integrations between ServiceNow and external systems. 🔄 Whether you're sending incident updates 🆘 or triggering external workflows ⚙️, webhooks help streamline automation 🤖.
In this guide, we'll walk through setting up a webhook in ServiceNow step by step 🛠️, covering everything from writing the script ✍️ to configuring the event registry 📜 and business rule 📌.
By the end, you'll have a fully functional webhook ✅ and the debugging skills 🕵️♂️ to troubleshoot issues effectively. 🚀
🔥 TL;DR
Whenever a new operation (Create 🆕 / Update ✏️ / Delete ❌ / Query 🔍) is performed on the Incidents table, we’ll:
1️⃣ Create a Business Rule 📌 that executes after the operation finishes (to grab the most up-to-date data).
2️⃣ Dispatch an Event 🚀 with two parameters:
- Current Data 📦 (which is needed in theory but doesn't work well for extracting data).
- sys_id 🆔 (a unique identifier for each record).
3️⃣ Write an Event Script 💻 that:
- Uses sys_id to query the Incidents table.
- Fetches the latest data 📅.
- Sends it to an external consumer 🌍.
By the end, we’ll have a real-time data synchronization ⚡ and a fully functional webhook for external integrations! 🔗🚀
1️⃣ Registering the Event in the Event Registry
We need first create an event.
Steps:
- Navigate to Plataform Analytics Administration > Data Collector > Event Registry.
- Click New to create a new event.
- Set Table to
Incident [incident]. - Add a description like Triggers a webhook when an incident is created or updated.
- Click Submit to save the event.
2️⃣ Creating the Script Action to Send an HTTP Request
The core of our webhook is a Script Action, which will send an outbound HTTP request when triggered. Let's start by writing the script that will handle this operation.
Steps:
- Navigate to System Policy > Events > Script Actions.
- Click New to create a new script.
- Set the Event name to match the one we'll register in the step above (e.g.,
incident.webhook). - Check the Active checkbox
- Use the following script to send an HTTP request:
(function executeWebhook(event) {
try {
const consumerEndpoint = "https://YOUR_ENDPOINT";
gs.info("🔥 Outbound Message");
const sysId = event.parm1;
var incidentTableRecord = new GlideRecord("incident");
incidentTableRecord.get(sysId);
incidentTableRecord.query();
if (incidentTableRecord.next()) {
const recordSysId = incidentTableRecord.getValue("sys_id");
const shortDescription = incidentTableRecord.getValue("short_description");
const description = incidentTableRecord.getValue("description")
const date = incidentTableRecord.getValue("sys_created_on");
const state = incidentTableRecord.getValue("state");
const incidentId = incidentTableRecord.getValue("number")
const priority = incidentTableRecord.getValue("priority");
var requestBody = {
shortDescription,
recordSysId,
date,
state,
incidentId,
description,
priority
};
gs.info("Sending Webhook Payload: " + JSON.stringify(requestBody));
var restMessage = new sn_ws.RESTMessageV2();
restMessage.setEndpoint(consumerEndpoint);
restMessage.setHttpMethod('POST');
restMessage.setRequestHeader('Content-Type', 'application/json');
restMessage.setRequestBody(JSON.stringify(requestBody));
var response = restMessage.execute();
var responseBody = response.getBody();
gs.info('✅ Webhook response: ' + responseBody);
} else {
gs.info("❌ No incidents found.");
}
} catch (error) {
gs.error('Error sending webhook: ' + error.message);
}
})(event);
- Click Submit to save the Script Action.
3️⃣ Creating a Business Rule to Trigger the Webhook
With the event in place, we need a Business Rule to fire it when an incident is created or updated.
Steps:
- Navigate to Activity Subscriptions > Adminsitration > Business Rules.
- Click New.
- Set Table to
Incident. - Set When to
After - Check Insert and Update checkboxes
- In the Advanced section, add the following script, updating it the event name created.
(function executeRule(current, previous /*null when async*/) {
gs.info("Executing Business Rule");
gs.eventQueue("your.event.here", current, current.sys_id); // UPDATE YOUR EVENT HERE
})(current, previous);
- Click Submit to save the Business Rule.
4️⃣ Time to create an incident 😏
Use REST API Explorer
Debugging and Troubleshooting
- Check the System Logs 🔥
If your webhook isn't working, go to System Logs > All and search for:
Verify the Event is Triggering
Use REST API Explorer
Conclusion 🎉
By following these steps, you've successfully created a webhook in ServiceNow using a Business Rule, Event Registry, and Script Action. This setup enables real-time integration with external services and can be customized further based on your needs. 🚀
Let me know if you have any questions or need enhancements! Happy coding! 👨💻🔥



Nice blog and informative content,
We are providing Best SERVICENOW Training in Hyderabad,
Thanks for sharing with us,
SERVICENOW Online Training in Hyderabad
SERVICENOW Training in Hyderabad
SERVICENOW Course in Hyderabad