Share Process Management Statuses with Slack

Contents

Overview

This article introduces how to post a message into a Slack (External link) channel from a Kintone App. When a workflow status of a record is proceeded to “Completed”, a script sends a request to Slack’s Incoming Webhook. A message including information about the record is then posted into a Slack channel.

Scenario

Although Slack has many bots in the marketplace, marketplace bots tend to only function for a particular scenario, which may not always fit in with the user’s needs.

Different database instances within Kintone can cover many scenarios depending on the user’s needs. CRMs, Project Management, Interview Notes, Task Lists, Expense Reports, PTO Request Forms are some examples. Kintone Apps tend to result in higher productivity if their Process Management settings have been enabled, which define a streamlined workflow for every record within the database.

Setting up the Connection

Prepare Slack

Create a Slack channel

Create a Slack channel (External link) that will receive notifications from Kintone.

Screenshot: The Slack platform.

Set up an Incoming Webhook

In Slack, open the Incoming Webhook Integration page. Check the Slack API documentation (External link) for more details.

Screenshot: The Slack platform with the Incoming webhook settings page open.

Choose a channel to which messages will be sent to. Click the Add Incoming WebHooks Integration button to set up an incoming webhook.

Screenshot: The Integration Settings page on the Slack platform.

Take note of the URL displayed in the Webhook URL settings, as it will be used in the next step. Fill out the rest of the form.

Prepare the App

Create the form

Create an App (External link) with the following fields.

Field Type Field Name Field Code
Text Task taskname
Date Due Date duedate
Text area Details details

Set the Process Management settings

In the settings of the App, navigate to App Settings, then to Process Management. Check the “Enable process management” checkbox. Set the following Status for the Status Settings.

Screenshot: The Status Settings for process management settings in a Kintone App.

Set the following settings for the Process Flow Settings

Screenshot: The Process Flow settings for process management settings in a Kintone App.

Save the settings, and click on Update App to apply the changes to the Kintone App.

Sample code

Prepare the following JavaScript code in a text editor and navigate to the Kintone App’s settings. Replace {subdomain} and {IncomingWebhookURL} with the necessary values. Upload the file into the Upload JavaScript for PC option of the JavaScript and CSS Customization settings (External link).

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
(function() {
  'use strict';
  kintone.events.on('app.record.detail.process.proceed', function(event) {
    if (event.nextStatus.value === 'Completed') {
      var thisUrl = 'https://{subdomain}.kintone.com/k/' + kintone.app.getId() + '/show#record=' + kintone.app.record.getId();
      var webhookUrl = '{IncomingWebhookURL}';
      var payload = {
        'text': '"<' + thisUrl + '|' + event.record.taskname.value + '>" has been completed!'
      };
      return new kintone.Promise(function(resolve, reject) {
        kintone.proxy(webhookUrl, 'POST', {}, payload, function(body, status, headers) {
          console.log(status, body);
          resolve(event);
        });
      });
    }
    return event;
  });
})();

After saving the settings and clicking on Update App, add a new record into the App. Proceed the Status of the record to “In progress”, then to “Completed”.

Animated GIF: The user proceeding the status of the record to Completed.

An event should be triggered, resulting in data being sent to Slack’s webhook. Check the Slack Channel to see if a message has been posted.

Screenshot: The Slack platform with a message posted from Kintone.

Reference