Product documentation Docs
    • English
    • Deutsch
    • 日本語
    • 한국어
    • Français
  • More Sites
    • Now Community
    • Developer Site
    • Knowledge Base
    • Product Information
    • ServiceNow.com
    • Training
    • Customer Success Center
    • ServiceNow Support Videos
  • Log in

Product documentation

  • Home
How search works:
  • Punctuation and capital letters are ignored
  • Special characters like underscores (_) are removed
  • Known synonyms are applied
  • The most relevant topics (based on weighting and matching to search terms) are listed first in search results
Topics are ranked in search results by how closely they match your search terms
  • A match on the entire phrase you typed
  • A match on part of the phrase you typed
  • A match on ALL of the terms in the phrase you typed
  • A match on ANY of the terms in the phrase you typed

Note: Matches in titles are always highly ranked.

  • Release version
    Table of Contents
    • HR Service Delivery
Table of Contents
Choose your release version
    Home Paris HR Service Delivery HR Service Delivery Emergency Response Management Emergency Outreach Configure Emergency Outreach notifications Create an Emergency Outreach notification channel

    Create an Emergency Outreach notification channel

    • Save as PDF Selected topic Topic & subtopics All topics in contents
    • Unsubscribe Log in to subscribe to topics and get notified when content changes.
    • Share this page

    Create an Emergency Outreach notification channel

    Create a notification channel to send health status requests using your company's preferred communication method, such as the Slack or Microsoft Teams collaboration platforms. Create the notification channel using a script or a subflow.

    Before you begin

    Role required: sn_imt_checkin.checkin_admin or admin

    About this task

    After you create a notification channel, you can select the channel when sending a notification. The channel uses the specified subject and body, and sends notifications to the users that you select when you send the health status request.

    For example, your company's IT network group has a Slack channel that they monitor more closely than email. Create a Slack notification channel. To communicate with IT network group members, select the group as the target audience and select the Slack notification channel.

    If the Email notification and Now Mobile Push notification check boxes are selected, all three notifications are sent. To use only the Slack notification channel, clear these two check boxes.

    Procedure

    1. Navigate to Emergency Outreach > Channels.
    2. Click New.
      New channel record with the script option selected and default script.
    3. Enter the name of your notification channel.
      Use a short name that indicates the communication method to make it easy for the requester to pick the correct channel.
    4. In the Subject field, enter the subject of your notification channel.
    5. In the Body field, enter the body message.
    6. Create a script notification channel.
      1. In the Notification type field, leave the default notification type of Script.
      2. In the Script field, replace the code in the comment with the script to connect to your channel.
        {
                    // sendNotification(responses.acknowledgementsGr.user.email, 
        channelGr.subject, channelGr.body);
                }
        For information about JavaScript APIs for GlideRecord, see GlideRecord - Scoped.
      3. Click Submit.

      The following example includes code to count the number of acknowledgements and survey instances generated when the notification is sent. It displays the number of acknowledgements and survey instances that succeeded. Use this information to review and handle errors that appear in the Delivery Log related list in the Outreach record.

      (function notify(responses, channelGr) {
          var record = responses.mode === 'acknowledgements' 
              ? responses.acknowledgementsGr 
              : responses.surveyInstancesGr;
          var totalCount = record.getRowCount();
          var numSent = 0;
          while (record.next()) {
              try {
                  // sendNotification(record.user.email, channelGr.subject, channelGr.body)
                  numSent += 1;
              } catch (err) {
                  gs.error('Error occurred: ' + err.message);
              }
          }
          return { total_count: totalCount, sent_count: numSent };
      })(responses, channelGr);
    7. Create a subflow notification channel.
      1. Create a subflow to use in the outreach notification.
        For information about creating, publishing, and testing subflows, see Subflows.
        Use the following inputs in the subflow that you create:
        • mode (string)
        • akcnowledgements (Records of sn_imt_checkin_check_in_acknowledgement)

          If the mode is acknowledgements, then acknowledgements are set to a valid GlideRecord and survey_instances is null.

        • survey_instances (Records of asmt_assessment_instance)

          If the mode is survey_instances, then survey_instances is set to a valid GlideRecord and acknowledgements is null.

        • channel (Reference of sn_imt_checkin_channels)
        The following outputs are optional:
        • total_count (integer)
        • sent_count (integer)

        To review these outputs, include the number of total acknowledgements or surveys versus the successful acknowledgements or surveys.

      2. Select the Subflow notification type.
        The Script section changes to Flow, and the Subflow reference field appears.
      3. Select the subflow that you created.
    8. Click Submit.

    When an outreach is sent using a custom notification channel, a Delivery Logs related list appears in the Outreach message.

    Delivery logs related list showing a failed log status.
    1. Test the notification channel for an outreach message, and open the failed record to review the error message.
    2. Fix errors that caused the notification to fail.
    3. Continue testing the notification channel until it no longer fails.

    Example: Slack channel script

    Note: The following script is for reference only. Refer to it when you develop a notification channel script for your environment.
    (function notify(responses, channelGr) {
        var createClient = function () {
            var client = new sn_ws.RESTMessageV2();      
            client.setRequestHeader('Authorization', 'Bearer xoxb-222222222222-1111111111111-000000000000000000000000');
            client.setRequestHeader("Accept", "application/json");
            client.setRequestHeader('Content-type', 'application/json');
            return client;
        };
    
        var getEmailToSlackIdMap = function (users) {
            var emailToSlackIdMap = {};
            for (var i = 0; i < users.length; i++) {
                var email = users[i].profile.email;
                if (email) {
                    emailToSlackIdMap[email] = users[i].id;
                }
            }
            return emailToSlackIdMap;
        };
    
        var runSlackCommand = function (method, params) {
            var client = createClient();
            client.setHttpMethod('post');
            client.setEndpoint('https://slack.com/api/' + method);
            client.setRequestBody(JSON.stringify(params));
            var response = client.execute();
            if (response.getStatusCode() < 200 || response.getStatusCode() > 299) {
                throw new Error('Failure running ' + method + ':\n' + response.getBody());
            }
    
            var body = JSON.parse(response.getBody());
            if (!body.ok) {
                throw new Error(body.error);
            }
    
            return body;
        };
    
        var sendMessage = function (userId, message) {
            var openConversationResponse = runSlackCommand('conversations.open', { users: userId });
            var channel = openConversationResponse.channel.id;
            runSlackCommand('chat.postMessage', { channel: channel, text: message });
        };
    
        var users = runSlackCommand('users.list').members;
        var emailToSlackIdMap = getEmailToSlackIdMap(users);
        var body = channelGr.getValue('body') || '<p></p>';
        var record = responses.mode === 'acknowledgements' ? responses.acknowledgementsGr : responses.surveyInstancesGr;
        var numSent = 0;
    
        while (record.next()) {
            var email = record.user.email + '';
    
            var link = responses.mode === 'acknowledgements'
                ? gs.getProperty('glide.servlet.uri') + record.getLink(true)
                : gs.getProperty('glide.servlet.uri') + 'sp?id=take_survey&instance_id=' + record.getUniqueValue();
    
            var message = body + '\n' + link;
    
            var slackId = emailToSlackIdMap[email];
            if (slackId) {
                sendMessage(slackId, message);
                numSent += 1;
            }
        }
    
        return { sent_count: numSent };
    })(responses, channelGr);

    Tags:

    Feedback
    On this page

    Previous topic

    Next topic

    • Contact Us
    • Careers
    • Terms of Use
    • Privacy Statement
    • Sitemap
    • © ServiceNow. All rights reserved.

    Release version
    Choose your release version

      Create an Emergency Outreach notification channel

      • Save as PDF Selected topic Topic & subtopics All topics in contents
      • Unsubscribe Log in to subscribe to topics and get notified when content changes.
      • Share this page

      Create an Emergency Outreach notification channel

      Create a notification channel to send health status requests using your company's preferred communication method, such as the Slack or Microsoft Teams collaboration platforms. Create the notification channel using a script or a subflow.

      Before you begin

      Role required: sn_imt_checkin.checkin_admin or admin

      About this task

      After you create a notification channel, you can select the channel when sending a notification. The channel uses the specified subject and body, and sends notifications to the users that you select when you send the health status request.

      For example, your company's IT network group has a Slack channel that they monitor more closely than email. Create a Slack notification channel. To communicate with IT network group members, select the group as the target audience and select the Slack notification channel.

      If the Email notification and Now Mobile Push notification check boxes are selected, all three notifications are sent. To use only the Slack notification channel, clear these two check boxes.

      Procedure

      1. Navigate to Emergency Outreach > Channels.
      2. Click New.
        New channel record with the script option selected and default script.
      3. Enter the name of your notification channel.
        Use a short name that indicates the communication method to make it easy for the requester to pick the correct channel.
      4. In the Subject field, enter the subject of your notification channel.
      5. In the Body field, enter the body message.
      6. Create a script notification channel.
        1. In the Notification type field, leave the default notification type of Script.
        2. In the Script field, replace the code in the comment with the script to connect to your channel.
          {
                      // sendNotification(responses.acknowledgementsGr.user.email, 
          channelGr.subject, channelGr.body);
                  }
          For information about JavaScript APIs for GlideRecord, see GlideRecord - Scoped.
        3. Click Submit.

        The following example includes code to count the number of acknowledgements and survey instances generated when the notification is sent. It displays the number of acknowledgements and survey instances that succeeded. Use this information to review and handle errors that appear in the Delivery Log related list in the Outreach record.

        (function notify(responses, channelGr) {
            var record = responses.mode === 'acknowledgements' 
                ? responses.acknowledgementsGr 
                : responses.surveyInstancesGr;
            var totalCount = record.getRowCount();
            var numSent = 0;
            while (record.next()) {
                try {
                    // sendNotification(record.user.email, channelGr.subject, channelGr.body)
                    numSent += 1;
                } catch (err) {
                    gs.error('Error occurred: ' + err.message);
                }
            }
            return { total_count: totalCount, sent_count: numSent };
        })(responses, channelGr);
      7. Create a subflow notification channel.
        1. Create a subflow to use in the outreach notification.
          For information about creating, publishing, and testing subflows, see Subflows.
          Use the following inputs in the subflow that you create:
          • mode (string)
          • akcnowledgements (Records of sn_imt_checkin_check_in_acknowledgement)

            If the mode is acknowledgements, then acknowledgements are set to a valid GlideRecord and survey_instances is null.

          • survey_instances (Records of asmt_assessment_instance)

            If the mode is survey_instances, then survey_instances is set to a valid GlideRecord and acknowledgements is null.

          • channel (Reference of sn_imt_checkin_channels)
          The following outputs are optional:
          • total_count (integer)
          • sent_count (integer)

          To review these outputs, include the number of total acknowledgements or surveys versus the successful acknowledgements or surveys.

        2. Select the Subflow notification type.
          The Script section changes to Flow, and the Subflow reference field appears.
        3. Select the subflow that you created.
      8. Click Submit.

      When an outreach is sent using a custom notification channel, a Delivery Logs related list appears in the Outreach message.

      Delivery logs related list showing a failed log status.
      1. Test the notification channel for an outreach message, and open the failed record to review the error message.
      2. Fix errors that caused the notification to fail.
      3. Continue testing the notification channel until it no longer fails.

      Example: Slack channel script

      Note: The following script is for reference only. Refer to it when you develop a notification channel script for your environment.
      (function notify(responses, channelGr) {
          var createClient = function () {
              var client = new sn_ws.RESTMessageV2();      
              client.setRequestHeader('Authorization', 'Bearer xoxb-222222222222-1111111111111-000000000000000000000000');
              client.setRequestHeader("Accept", "application/json");
              client.setRequestHeader('Content-type', 'application/json');
              return client;
          };
      
          var getEmailToSlackIdMap = function (users) {
              var emailToSlackIdMap = {};
              for (var i = 0; i < users.length; i++) {
                  var email = users[i].profile.email;
                  if (email) {
                      emailToSlackIdMap[email] = users[i].id;
                  }
              }
              return emailToSlackIdMap;
          };
      
          var runSlackCommand = function (method, params) {
              var client = createClient();
              client.setHttpMethod('post');
              client.setEndpoint('https://slack.com/api/' + method);
              client.setRequestBody(JSON.stringify(params));
              var response = client.execute();
              if (response.getStatusCode() < 200 || response.getStatusCode() > 299) {
                  throw new Error('Failure running ' + method + ':\n' + response.getBody());
              }
      
              var body = JSON.parse(response.getBody());
              if (!body.ok) {
                  throw new Error(body.error);
              }
      
              return body;
          };
      
          var sendMessage = function (userId, message) {
              var openConversationResponse = runSlackCommand('conversations.open', { users: userId });
              var channel = openConversationResponse.channel.id;
              runSlackCommand('chat.postMessage', { channel: channel, text: message });
          };
      
          var users = runSlackCommand('users.list').members;
          var emailToSlackIdMap = getEmailToSlackIdMap(users);
          var body = channelGr.getValue('body') || '<p></p>';
          var record = responses.mode === 'acknowledgements' ? responses.acknowledgementsGr : responses.surveyInstancesGr;
          var numSent = 0;
      
          while (record.next()) {
              var email = record.user.email + '';
      
              var link = responses.mode === 'acknowledgements'
                  ? gs.getProperty('glide.servlet.uri') + record.getLink(true)
                  : gs.getProperty('glide.servlet.uri') + 'sp?id=take_survey&instance_id=' + record.getUniqueValue();
      
              var message = body + '\n' + link;
      
              var slackId = emailToSlackIdMap[email];
              if (slackId) {
                  sendMessage(slackId, message);
                  numSent += 1;
              }
          }
      
          return { sent_count: numSent };
      })(responses, channelGr);

      Tags:

      Feedback

          Share this page

          Got it! Feel free to add a comment
          To share your product suggestions, visit the Idea Portal.
          Please let us know how to improve this content

          Check any that apply

          To share your product suggestions, visit the Idea Portal.
          Confirm

          We were unable to find "Coaching" in Jakarta. Would you like to search instead?

          No Yes
          • Contact Us
          • Careers
          • Terms of Use
          • Privacy Statement
          • Sitemap
          • © ServiceNow. All rights reserved.

          Subscribe Subscribed Unsubscribe Last updated: Tags: January February March April May June July August September October November December No Results Found Versions Search preferences successfully updated My release version successfully updated My release version successfully deleted An error has occurred. Please try again later. You have been unsubscribed from all topics. You are now subscribed to and will receive notifications if any changes are made to this page. You have been unsubscribed from this content Thank you for your feedback. Form temporarily unavailable. Please try again or contact  docfeedback@servicenow.com  to submit your comments. The topic you requested does not exist in the release. You were redirected to a related topic instead. The available release versions for this topic are listed There is no specific version for this documentation. Explore products Click to go to the page. Release notes and upgrades Click to open the dropdown menu. Delete Remove No selected version Reset This field is required You are already subscribed to this topic Attach screenshot The file you uploaded exceeds the allowed file size of 20MB. Please try again with a smaller file. Please complete the reCAPTCHA step to attach a screenshot
          Log in to personalize your search results and subscribe to topics
          No, thanks Login