The CreatorCon Call for Content is officially open! Get started here.

Teams in SOW: Chat title cannot contain ':' character.

Moritz Becker1
Tera Contributor

Hi Everybody,

This is not a question but a solution.

This issue will appear if, for some reason, an incident or work order title contains a ":", as Microsoft Teams chat titles must not contain colon characters.

 

MoritzBecker1_0-1759420824196.png

Unfortunately, some autogenerated incidents and work orders will include a colon, and it’s not really practical to have a business rule remove or replace it in all short descriptions.

I dug deeper and traversed various UI pages, Script Includes, and other components to find where the title was generated so I could modify that logic.

As it turns out, ServiceNow uses a utility called AbstractChatUtil — part of the Collaboration Services application — which contains many functions relevant to integrations like Microsoft Teams.

Inside that utility is a function called getChatTitle. This function is responsible for generating the chat title, and the result is used directly by the MS Teams integration (and likely others).

You can modify this function to replace colon characters with a dash or another character of your choosing.

To do so, go to the table Script Includes (sys_script_include) and search for AbstractChatUtil.

Note: This is a wrapper that extends AbstractChatUtilSNC.

Now, add the following function (this will overrule the function in the superclass located in AbstractChatUtilSNC, without  a huge problem with skipped updates)

getChatTitle: function(gr, descriptionField) {
		var d = function(){
			descriptionField = descriptionField || 'short_description';
			if (gr.getTableName() == this.TABLE.CATALOG_TASK) {
				var reqItemGr = gr.request_item.getRefRecord();
				if (reqItemGr.isValidRecord() && reqItemGr.isValidField(descriptionField) && reqItemGr[descriptionField].canRead() && reqItemGr.getValue(descriptionField)) {
					if (reqItemGr.isValidField('number') && reqItemGr.number.canRead() && reqItemGr.number)
						return reqItemGr.number + (gs.nil(reqItemGr.short_description) ? '' : ' - ' + reqItemGr.short_description);
					else
						return gs.nil(reqItemGr.short_description) ? '' : reqItemGr.short_description;
				} else
					return reqItemGr.number || '';
			}

			if (gr.isValidField('number')) {
				if (gr.isValidField(descriptionField) && !gs.nil(gr.getValue(descriptionField)))
					return gr.number + " - " + gr.getValue(descriptionField);
				else
					return gr.number + '';
			}
			return '';
		};
		return (d.bind(this))().replace(/ ?:/gm," -");
        
    },

After modification, the full Script Include may look like this:

var AbstractChatUtil = Class.create();
AbstractChatUtil.prototype = Object.extendsObject(sn_tcm_collab_hook.AbstractChatUtilSNC, {
    initialize: function() {
        sn_tcm_collab_hook.AbstractChatUtilSNC.prototype.initialize.call(this);
    },
	getChatTitle: function(gr, descriptionField) {
		var d = function(){
			descriptionField = descriptionField || 'short_description';
			if (gr.getTableName() == this.TABLE.CATALOG_TASK) {
				var reqItemGr = gr.request_item.getRefRecord();
				if (reqItemGr.isValidRecord() && reqItemGr.isValidField(descriptionField) && reqItemGr[descriptionField].canRead() && reqItemGr.getValue(descriptionField)) {
					if (reqItemGr.isValidField('number') && reqItemGr.number.canRead() && reqItemGr.number)
						return reqItemGr.number + (gs.nil(reqItemGr.short_description) ? '' : ' - ' + reqItemGr.short_description);
					else
						return gs.nil(reqItemGr.short_description) ? '' : reqItemGr.short_description;
				} else
					return reqItemGr.number || '';
			}

			if (gr.isValidField('number')) {
				if (gr.isValidField(descriptionField) && !gs.nil(gr.getValue(descriptionField)))
					return gr.number + " - " + gr.getValue(descriptionField);
				else
					return gr.number + '';
			}
			return '';
		};
		return (d.bind(this))().replace(/ ?:/gm," -");
        
    },

    type: 'AbstractChatUtil'
});

The magic happens in the final line of the function, where the regular expression replaces any colon (optionally preceded by a space) with a dash.

You can tweak the regex or replacement character as needed — just make sure the colon is removed to prevent the Microsoft Teams error.

And that’s it — your chat function in ServiceNow should now work without triggering the invalid character error.

0 REPLIES 0