Customizing Microsoft Teams Collaboration Chat

rohanaditya
Kilo Sage

Overview

ServiceNow's Microsoft Teams Collaboration Chat allows users to start a Microsoft Teams conversation directly from a ServiceNow record, making it easy to collaborate with subject matter experts without leaving Teams.

By default, every new collaboration chat begins with the standard compliance message: "This chat log may be saved to better serve you in the future."

 

Default Teams compliance message

 

While this satisfies compliance requirements, it doesn't provide participants with a quick way to navigate back to the originating ServiceNow record.

This article demonstrates how to extend the out-of-the-box functionality so that, immediately after the compliance message is posted, Microsoft Teams automatically sends another message containing direct links to the originating ServiceNow record.


Solution

Rather than replacing the default compliance message, this solution extends the existing behavior.

After the standard welcome message is sent, a second Teams message is automatically posted with direct links to the originating record.

  • Incident records display:
    • Open in Employee Center
    • Open in Agent Workspace
  • All other supported tables display:
    • Open in Agent Workspace

This provides users with one-click navigation back to ServiceNow directly from Microsoft Teams.


Step 1: Create a Child Script Include

To keep the customization upgrade-safe, create a child Script Include that extends MSTeamsChatUtilSNC instead of modifying the out-of-the-box Script Include.

Override the runSendCardToChatFlow() method and invoke the parent implementation first to preserve the native functionality.

var result = sn_tcm_collab_hook.MSTeamsChatUtilSNC.prototype.runSendCardToChatFlow.call(
    this,
    chatId,
    message,
    tableName,
    sourceSysId
);

Step 2: Generate Dynamic Record Links

Retrieve the instance URL dynamically using the glide.servlet.uri system property. This avoids hardcoding environment-specific URLs and works across Development, Test, and Production instances.

var instanceUrl = gs.getProperty('glide.servlet.uri');

var sowUrl =
    instanceUrl +
    "now/sow/record/" +
    tableName +
    "/" +
    sourceSysId;

For Incident records, generate an Employee Center URL as well.

var portalUrl =
    instanceUrl +
    "esc?id=ticket&table=incident&sys_id=" +
    sourceSysId;

Step 3: Build and Send the Teams Message

Format the custom message as HTML before sending it to Microsoft Teams.

var customPayload = {
    body: {
        contentType: "html",
        content: htmlMessage
    }
};

Reuse the existing Flow Designer action to post the message.

sn_fd.FlowAPI.getRunner()
    .action('sn_tcm_collab_hook.send_message_to_microsoft_teams_chat')
    .inForeground()
    .withInputs(inputs)
    .run();

Result

After a collaboration chat is created:

  1. The standard compliance message is posted.
  2. A second message is automatically sent with links to the originating ServiceNow record.

Incident records include:

  • Open in Employee Center
  • Open in Agent Workspace

All other supported tables include:

  • Open in Agent Workspace

Teams message with record links


Benefits

  • Preserves the out-of-the-box compliance message.
  • Adds direct navigation back to the originating ServiceNow record.
  • Supports both Employee Center and Agent Workspace for Incident records.
  • Reuses the existing Microsoft Teams integration and Flow Designer action.
  • Remains upgrade-safe by extending the base Script Include instead of modifying it.

Complete Script Include

var MSTeamsChatUtil = Class.create();
MSTeamsChatUtil.prototype = Object.extendsObject(sn_tcm_collab_hook.MSTeamsChatUtilSNC, {
    initialize: function() {
        sn_tcm_collab_hook.MSTeamsChatUtilSNC.prototype.initialize.call(this);
    },

    runSendCardToChatFlow: function(chatId, message, tableName, sourceSysId) {

        // Send the standard OOB message first
        var result = sn_tcm_collab_hook.MSTeamsChatUtilSNC.prototype.runSendCardToChatFlow.call(
            this,
            chatId,
            message,
            tableName,
            sourceSysId
        );

        // Prevent loops and ensure valid record parameters
        if (message && message.indexOf('now/sow/record') === -1 && tableName && sourceSysId) {

            var instanceUrl = gs.getProperty('glide.servlet.uri');
            var sowUrl = instanceUrl + "now/sow/record/" + tableName + "/" + sourceSysId;

            var htmlMessage = "View this record here:<br><br>";

            // Show Employee Portal link first for Incidents
            if (tableName === 'incident') {
                var portalUrl = instanceUrl + "esc?id=ticket&table=incident&sys_id=" + sourceSysId;

                htmlMessage +=
                    "<a href='" + portalUrl + "'><b>Open in Employee Portal</b></a>" +
                    " or ";
            }

            // Show Agent View link
            htmlMessage +=
                "<a href='" + sowUrl + "'><b>Open in Agent View</b></a>";

            var customPayload = {
                body: {
                    contentType: "html",
                    content: htmlMessage
                }
            };

            var inputs = {};
            inputs.chat_id = chatId;
            inputs.payload = JSON.stringify(customPayload);
            inputs.credential_alias = this.getTeamsChatCredentialsAliasGr();

            try {
                sn_fd.FlowAPI.getRunner()
                    .action('sn_tcm_collab_hook.send_message_to_microsoft_teams_chat')
                    .inForeground()
                    .withInputs(inputs)
                    .run();
            } catch (ex) {
                gs.error("Failed to send custom HTML link to Teams: " + ex.getMessage());
            }
        }

        return result;
    },

    type: 'MSTeamsChatUtil'
});

Conclusion

By extending MSTeamsChatUtilSNC instead of modifying the out-of-the-box implementation, you can enhance Microsoft Teams Collaboration Chat while remaining upgrade-safe. Users continue to receive the standard compliance message, followed by a second message containing direct links back to the originating ServiceNow record, making collaboration more efficient without changing the native experience.

0 REPLIES 0