Selva Arun
Mega Sage
Mega Sage

🚀 Custom ServiceNow to Slack Integration for Change Request Approvals

This guide will walk you through setting up a custom integration between ServiceNow and Slack. The integration will:

  • Send a Slack message when a Normal Change Request is created in ServiceNow.
  • Allow approvers to Approve/Decline directly in Slack.
  • Automatically update the Change Request status in ServiceNow.
  • Post a response back to Slack, stating that the Change Request has been updated after approval or rejection.

SelvaArun_0-1741101329955.png

 

🔹 1️⃣ Create a Slack App

We need to create a custom Slack App that sends and receives messages.

Step 1: Create a Slack Bot

  1. Go to Slack API Apps: Visit the Slack API Apps page.
  2. Click "Create New App" → Select "From Scratch".
  3. Enter App Name: For example, ServiceNow Approvals.
  4. Select your Slack Workspace: Choose the workspace where the bot will be installed.

Step 2: Enable Slack API Features

  1. Go to OAuth & Permissions.
  2. Add the following Bot Token Scopes:
    • chat:write (Send messages to channels)
    • commands (Create interactive buttons)
    • incoming-webhook (Receive responses)

SelvaArun_1-1741101353401.pngSelvaArun_2-1741101364845.png

 

  1. Install the App to Your Workspace:
    • Click Install App.
    • Copy the Bot Token (starts with xoxb-...).

Step 3: Invite the App to the Channel

  1. Invite the newly created Slack bot to the channel (in this case, the #itsm channel) Right click on the channel and click on Integration and add apps.

SelvaArun_3-1741101375746.png

 

🔹 2️⃣ Configure ServiceNow to Send Slack Messages

We will use ServiceNow Flow Designer and REST Messages to send Slack notifications when a Change Request is created.

Step 1: Create a REST Message to Send Messages to Slack

  1. Navigate to: System Web Services → Outbound → REST Message.
  2. Click New and enter:
  3. Add HTTP Headers:
    • Authorization: Bearer <YOUR_SLACK_BOT_TOKEN>
    • Content-Type: application/json

SelvaArun_4-1741101397106.png

Set the Request Body (JSON) and Save & Test:

  1. {
  2.   "channel": "#itsm",
  3.   "text": "🚀 A New Change Request Needs Approval!",
  4.   "attachments": [
  5.     {
  6.    "text": "${changeRequestId} - ${changeRequestDescription}",
  7.       "fallback": "Approve or Reject",
  8.       "callback_id": "${changeRequest}",
  9.       "actions": [
  10.         {
  11.           "name": "approve",
  12.           "text": " Approve",
  13.           "type": "button",
  14.           "value": "approved"
  15.         },
  16.         {
  17.           "name": "decline",
  18.           "text": " Decline",
  19.           "type": "button",
  20.           "value": "declined"
  21.         }
  22.       ]
  23.     } 

SelvaArun_5-1741101414202.png

SelvaArun_6-1741101507803.png

 

 

🔹 3️⃣ Capture Approvals in Slack and Update ServiceNow

Slack buttons require a webhook endpoint to send responses back to ServiceNow, which will process the approval or rejection and update the Change Request status.

Step 1: Create an Inbound Webhook in ServiceNow

  1. Go to: System Web Services → Scripted REST APIs.
  2. Click New:
    • Name: Slack Change Approval
  3. Check Override default supported request formats and Override default supported response formats to:
    • application/x-www-form-urlencoded

SelvaArun_7-1741101533989.pngSelvaArun_8-1741101545850.png

 

  1. Create a new Resource (POST method):
    • Name: process_approval
    • Relative Path: process_approval

 

SelvaArun_9-1741101554712.png

 

 

Step 2: Insert the Script to Process Slack Responses

Add the following script to handle incoming responses from Slack and update the Change Request status in ServiceNow:

(function process(request, response) {

    try {

        var payloadString = request.queryParams.payload;

 

        if (!payloadString) {

            gs.error("Missing payload parameter.");

            response.setStatus(400);

            response.setHeader("Content-Type", "application/x-www-form-urlencoded");

            response.setBody("error=" + encodeURIComponent("Missing payload parameter"));

            return;

        }

 

        var payloadObj;

        try {

            payloadObj = JSON.parse(payloadString);

        } catch (e) {

            gs.error("Error parsing payload: " + e);

            response.setStatus(400);

            response.setHeader("Content-Type", "application/x-www-form-urlencoded");

            response.setBody("error=" + encodeURIComponent("Invalid JSON format in payload"));

            return;

        }

 

        var approvalStatus = payloadObj.actions[0].value;

        var changeRequestNumber = payloadObj.callback_id;

 

        var gr = new GlideRecord('sysapproval_approver');

        gr.addQuery('sysapproval.number', changeRequestNumber);

        gr.query();

 

        if (gr.next()) {

            gr.state = approvalStatus === "approved" ? 'approved' : 'rejected';

            if (approvalStatus === "declined") gr.comments = "Declined via Slack";

            gr.update();

            gs.info("Change Request " + changeRequestNumber + " updated successfully.");

 

            var slackMessage = {

                "channel": "#itsm",  // Specify the channel to post the message in

                "text": "Change request " + changeRequestNumber + " has been " + approvalStatus + " as per your response.",

                "response_type": "in_channel"  // Ensures the message is visible in the channel

            };

 

            var r = new sn_ws.RESTMessageV2('Slack - Send Message (OAuth)', 'Slack - Send Message');

            r.setRequestBody(JSON.stringify(slackMessage));

            var res = r.execute();

            var responseBody = res.getBody();

            var statusCode = res.getStatusCode();

            gs.info("Slack response: " + responseBody + " Status Code: " + statusCode);

 

            response.setStatus(200);

            response.setHeader("Content-Type", "application/x-www-form-urlencoded");

            response.setBody("success=true&message=" + encodeURIComponent("Approval status updated"));

        } else {

            gs.error("Change Request not found: " + changeRequestNumber);

            response.setStatus(404);

            response.setHeader("Content-Type", "application/x-www-form-urlencoded");

            response.setBody("error=" + encodeURIComponent("Change request not found"));

        }

    } catch (e) {

        gs.error("Error processing Slack approval: " + e.toString());

        response.setStatus(500);

        response.setHeader("Content-Type", "application/x-www-form-urlencoded");

        response.setBody("error=" + encodeURIComponent("Internal server error"));

    }

})(request, response);

Step 3: Connect Slack to ServiceNow Webhook

  1. Go to Slack App Settings → Interactivity & Shortcuts.
  2. Enable Interactivity:
  3. Save Changes.

SelvaArun_10-1741101572864.png

 

🔹 3️⃣ Automating the Process with Flow Designer and Integration Hub:

Step 1: Activate Integration Hub Plugins

  1. Navigate to: System Definition → Plugins.
  2. Search for the following plugins: ServiceNow IntegrationHub Starter Pack Installer, ServiceNow IntegrationHub Standard Pack Installer /ServiceNow IntegrationHub Professional Pack Installer / ServiceNow IntegrationHub Enterprise Pack Installer (install anyone of these).
  3. Click Activate next to each of these plugins.

Step 2: Create an Action in Flow Designer

Once Integration Hub is activated, you need to create an action that will be used to send the Slack message.

  1. Go to Flow Designer:
    • Navigate to: Flow Designer → Designer.
    • Click New to create a new action.
  2. Create the Action:
    • Name: Send Slack Approval Request
    • Table: Select Global or a specific table that aligns with your Change Request.
    • Type: Select Action.
  3. Add a Step to Call the REST Message:
    • Channel: Use the Channel input.
    • Text: Populate the text dynamically with the necessary information (like Change Request number).
    • Click the + sign to add a new step.
    • Choose the REST Message option and create a credential by clicking on the + icon next to credential alias, select Basic Auth and Give your slack username and BOT Token and select the connection as Define Connection Inline.

SelvaArun_11-1741101611182.png

 

    • Select the previously created REST message (Slack - Send Message).

SelvaArun_12-1741101656028.pngSelvaArun_13-1741101664838.png

 

    • Map the action inputs to the REST message fields:
  1. The data from the REST message gets copied over to the flow Rest Step which would automatically create the variables too. Save the Action and Publish it.

Step 3: Use the Action in a Flow

Now that the action has been created, it needs to be used within a flow to automate the Slack notification process.

  1. Create a New Flow:
    • Navigate to: Flow Designer → Designer.
    • Click New to create a new flow.
  2. Define the Flow Trigger: Choose a trigger that will initiate the flow. For a Change Request, you can use the Record Triggered Flow.
    • Table: Change Request.
    • Trigger: Select Created or any relevant trigger (e.g., when the Change Request enters a specific state like "Approval").
  1. Add the Action:
    • In the Flow Steps, click the + sign and select Action.
    • Choose the action you created earlier (Send Slack Approval Request).
    • Map the necessary fields from the Change Request record to the inputs for the action (e.g., Channel, Change Request Number, etc.).
  1. Save and Activate the Flow.

SelvaArun_14-1741101678845.pngSelvaArun_15-1741101687877.png

 

🔹 4️⃣ Testing the Integration

  1. Create a Normal Change Request in ServiceNow.
  1. Slack will send an approval message to the #itsm channel.
  1. Approvers can click Approve or Decline directly in Slack.

SelvaArun_16-1741101716224.png

 

  1. The Change Request status will be automatically updated in ServiceNow, and a response will be posted back to Slack, confirming that the Change Request has been updated.

SelvaArun_17-1741101728351.png

 

🎯 Summary

  • ServiceNow REST Message sends approval requests to Slack.
  • Slack Buttons allow approvers to approve/decline directly.
  • ServiceNow Webhook processes approvals and updates the Change Request status.
  • Bot Token Scopes: chat:write, commands, incoming-webhook (for bot interaction).
  • User Token Scopes: Ensure the app has the necessary permissions to perform the actions on behalf of users.
  • Ensure that the Slack App is invited to the #itsm channel to receive notifications and handle approvals.

SelvaArun_0-1741101933120.png

 

 

📢 For a detailed walkthrough, check out our YouTube video:
Learn ServiceNow to Slack Integration for Change Request Approvals!

If you found this helpful, please like, share, and subscribe to our channel. I'd love to hear your feedback in the comments!

 

If you believe the solution provided has adequately addressed your query, could you please **mark it as 'Helpful'**. This will help other community members who might have the same question find the answer more easily.

 

Thank you for your consideration.

Selva Arun

Version history
Last update:
‎03-04-2025 07:26 AM
Updated by:
Contributors