logo

NJP

Teams Integration with Incidents - Start new chat from Incident form using Microsoft Deep Link and UI Macros

Import · Jan 08, 2020 · article

Hi Folks,

I've done some research and looked into adding a UI Macro button onto our incident form for our technicians to start a new Teams chat with that specific caller. I drew information from a previous post on the community. I'll walk you through the steps I took to add in more content to the chat integration. I am a SN Admin, self-taught developer. If you're sitting in a similar seat as me, you can most definitely tackle this small project and add in a cool integration for your team!

We will be using a Microsoft Deep Link to create a Teams chat. If you haven't heard of this, take some time to read the Microsoft doc. The basics of the Deep Link is to pass parameters through a URL to open a new Teams chat (in browser or on your desktop client - this is set by users). I will be using the "users" and "message" parameters to auto-open a chat with a specific user and prepopulate the message content of that chat.

Don't forget to create an update set for the changes you're about to make!

Adding Icon to System UI Images:

Add the Teams Icon to ServiceNow (or create your own icon).

  1. Go to System UI > Images
  2. Create a new Image and call it "teams.png", make sure the image is active and tagged under the appropriate category.
  3. Note the height/width of your image - you will want something smaller for the icon size

image

Create New UI Macro:

We will create a new UI Macro that will generate the Deep Link URL based off the parameters we want to pass through to Teams.

  1. Navigate to System UI > UI Macros and create a new UI Macro
  2. Name the UI Macro "teams_chat"
  3. In the script section, enter the following:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core"
xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<a class="btn-default;" id="${jvar_n}" onclick="invokeChat('${ref}');">
              <img src="teams.png" width="30"  title="Teams Chat" alt="${gs.getMessage('Click to open Teams chat')}" />
</a>
<script>
function invokeChat(reference) {

var prefix = 'https://teams.microsoft.com/l/chat/0/0?users=';
var firstname = g_form.getReference('caller_id').first_name;
var user = g_form.getReference('caller_id').email;
var subject = '&amp;amp;message=Hi ' + firstname + ', this is regarding your Incident ' + g_form.getValue('number') + ': ' + g_form.getValue('short_description');

var w = getTopWindow();
var url = prefix + user + subject;
w.open(url);
}
</script></j:jelly>

A couple of notes about the code:

View original source

https://www.servicenow.com/community/itsm-articles/teams-integration-with-incidents-start-new-chat-from-incident/ta-p/2305854