In the last 3 posts, we have covered everything from what Webhooks are and how they can be used with popular collaboration platforms like Cisco Webex and Microsoft Teams to generate event notifications. I am concluding this series with this post where we are going to take everything we have learned so far & build something that can solve a real production problem faced by Operations teams. In this post, we will go over the process of creating Business Rules in ServiceNow and use it along with ServiceNow’s outbound REST functionality to mimic the behavior of a traditional outbound Webhook. On the opposite side, we will be using Cisco Webex’s incoming webhook to receive the message being sent by ServiceNow. The table of contents is given below. You can click on the link to jump to the relevant section.
- Sample Problem Statement
- Setting up ServiceNow Instance
- Configuring ServiceNow Business Rules
- Final Webhook Demonstration
I have linked my previous articles from this series below. I would request you to go through them first so that you are clear on the working principle of Webhooks and their relationship with modern collaboration platforms.
- Introduction to Webhooks
- Setting up Outgoing Webhooks with MS Teams
- How to use Incoming Webhooks with Cisco Webex
Sample Problem Statement
An organization is using ServiceNow as their primary ticketing tool to log incidents & service requests. The tickets are categorized under different priorities based on the severity level of the issue. From support point of view, it would behoove us to have some sort of a mechanism where the Operations team is notified of every high priority ticket (P1/P2) as quickly as possible. This can be accomplished in one of the following three ways:
- Super Inefficient – You can monitor the ticket queue continuously & take action as soon as you see any P1/P2 ticket in the queue.
- Mildly efficient – You can choose to be notified via an email from Service Now when a P1/P2 comes into the queue.
- Most efficient but requires $$$ – You can integrate Service Now with third party applications like PagerDuty which can notify the team’s point of contact via phone call or a text message.
All of the above mentioned three methods suffer from some challenge or the other. The first method is cheap but lacks efficiency while the third method is super efficient but requires additional money. What if there was a way to implement a method which is not only extremely efficient but also doesn’t cost anything extra ? This is where the power of Webhooks can be exploited alongwith Service Now and collaboration platforms like Webex/MS Teams.
Setting up ServiceNow Instance
If your organization has some sort of a dev environment already then you can use its Service Now to setup & test the following configuration. If that’s not available, then you can setup an account on Service Now developer network and spin up your own personal instance for testing.
- Go to https://developer.servicenow.com/
- Click on “Request Instance”.

- Select the Service Now release that you want to use to build your solution and click on “Request”.

It will take a few minutes at the end of which you should have the login details for the newly launched instance. You can either click on “Open Instance” directly or click in the URL and login with the username/password information provided here.

At this point, you should see something like the following

Configuring ServiceNow Business Rules
- In order to setup a “Business Rule”, go to All –> System Definition –> Business Rule

- Click on “New” on the top right corner to create a new “Business Rule”.

- On the New Business Rule page,
- Give it a name.
- Select the table on which you want this Business Rule to run. We are selecting the “Task” table for our use case.
- Check “Advanced” option to activate the “Advanced” tab.
- Add the appropriate filter condition. In our example, we want to be notified whenever a P2 ticket comes into the queue.

- Click on “Advanced” tab. This is where we will need to add a bit of custom Javascript code.

- Paste the following code in the function. This is a very simple Javascript code that is doing the following:
- Creating a new variable & initializing it with the “RESTMessageV2” method.
- Setting up an endpoint – This is the webhook URL where the message will be sent. You must have received this URL when you setup Incoming Webhook in Webex. This is explained in my previous article linked here.
- Setting up the REST method (POST) and content-type application header.
- It is then fetching the “Task number” and sending it as a part of the JSON payload.
var r = new sn_ws.RESTMessageV2();
r.setEndpoint("https://webexapis.com/v1/webhooks/incoming/Y2lzY29zcGFyazovL3VzL1dFQkhPT0svMDBjMWVlOGMtYzBmMy00YT");
r.setHttpMethod("post");
r.setRequestHeader("content-type","application/json");
var number = current.getValue("number");
var obj = {"text" : "A P2 priority ticket has been opened - " + number};
var body = JSON.stringify(obj);
gs.info("Webhook body: " + body);
r.setRequestBody(body);
var response = r.execute();
- Finally, you should have something like the following

At this point, your Service Now business rule is in place which means that as soon as a P2 ticket comes into your queue, this business rule will be executed. As a result, it will trigger an outbound REST POST message to the Webex Incoming Webhook URL.
Final Webhook Demonstration
- Let’s now create a sample P2 ticket.

- As soon as I created this ticket, I received a notification in the Webex app.

This concludes our series on Webhooks. I hope you have found this 4 part series useful & you are ready to implement these learnings towards solving different use cases specific to your Operations environments.
Please feel free to drop your feedback/suggestions, if any. Until then, Happy Learnings!!
