
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 02:03 AM
Hi Community,
we are looking into enabling the Teams Chat in for Records in our instance. We currently face the Challange, that not all our users are enabled in Teams but are listed in the Recommended Contacts. But we would like to hide those to avoid mistakes by the users:
Is there a way to hide those accounts (which are already flagged as "not on Teams" in the recommendation/User picker?
Thanks a lot for any hint on how to solve this!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 12:42 AM
Thanks again for the Hints. Unfortunately the ChatRestrictedTaskParticipants Script Include lets you only filter the Users that are selectable over the User picket ad the top:
But with the Help of my Colleagues I found now a way to filter the Users shown in the Recommended area by adjusting the "loadRecommended" Function in the "msteams_communication_swarm" UI Page.
To adchive this I only needed to add the condition "*.isValidTeamsUser == true" in the Sections adding users to the Modal. Here is an extract of the Function with comments where I made the Changes:
// Called when we get a response from the 'addLoadEvent' function
function loadRecommended(response) {
var userId = gInputData.userId;
hideLoadingIcon();
if (typeof response === 'string') {
if (response.length === 0)
return;
var result = JSON.parse(response);
if (result.error) {
// Return in case of error when fetch user details
showAlert(formatMessage(getMessage('{0}'), result.error), 'error', 10000);
return;
}
addToAvailableList(result);
var side = 'left';
for (var i = 0; i < result.length; i++) {
var item = result[i];
if (Array.isArray(item.users)) {
// add GroupName to Selected or add individual group members
if (item.showGroupName) {
addSwarmOption(result[i], side);
} else {
for (var j = 0; j < item.users.length; j++) {
if (userId != '' && item.users[j].id == userId){
addSwarmOption(item.users[j], 'right');
}
else if(item.users[j].isValidTeamsUser == true){ //added the isValidTeamsUser condition
addSwarmOption(item.users[j], side);
}
}
}
} else {
if (userId != '' && item.id == userId && item.isValidTeamsUser == true) { //added the isValidTeamsUser condition
addSwarmOption(item, 'right');
}
else if(item.isValidTeamsUser == true){ //added the isValidTeamsUser condition
addSwarmOption(item, side);
}
}
}
}
// get and save the selected values on the right of the slush bucket
var array = chatSwarmSlush.getValues(chatSwarmSlush.getRightSelect());
var r = array.join(",");
chatSwarmSlush.saveRightValues(r);
setModalParentHeight();
}
With this I could finally achieve that the Recommended Users in the left of the Modal are only Users with a MS Teams Account
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 04:39 AM - edited 01-16-2024 04:41 AM
The Script Includes involved are:
- MSTeamsChatRestrictedTaskParticipants
- ChatRestrictedTaskParticipants
MSTeamsChatRestrictedTaskParticipants has Table definitions that define which tables/fields should be used to Recommend participants. string
This post gives an examples of how to add a Table and it's Fields.
For your case, to limit Users, if they have a linked Teams account then they would have an entry in Table: provider_user_map
In Script Include: ChatRestrictedTaskParticipantsSNC
At line 96 (if not customized you will find the following function) . getRelatedUsersCondition
//This method is used to get the condition to limit the users you want to add in the chat. Its fine to add sys_user sysId in the condition if there are limited number of users coming from different sources but its better to use a generic condition to limit the condition size. For e.g. 'active=true^internal_integration_user=false
getRelatedUsersCondition: function(table, sysId) {
var values = [];
var sourceGr = new GlideRecord(table);
if (sourceGr.get(sysId)) {
values = this.chatUtil.getUsersFromSourceRecord(sourceGr);
}
values = values.concat(this.chatUtil.getApprovers(table, sysId));
values = this.chatUtil.filterDuplicates(values);
values = this.filterUsersWithValidHRProfiles(table, values);
//This is the encoded condition to query on sys_user table
var encodedCond = 'active=true^sys_idIN' + values;
return encodedCond;
},
You should be able to amend that and filter out the users you do not want to appear by amending the encodedCond string.
Regards
Paul

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 12:04 AM
Hi Paul,
thabnks a lot for this. I hade a look and from my understanding and the ServiceNow Documentation I should be able to override the getRelatedUsersCondition frunction from the ChatRestrictedTaskParticipantsSNC script include by adding the adjusted version (with edited encoded Query) in the ChatRestrictedTaskParticipants script include as it only extends ChatRestrictedTaskParticipantsSNC. But onfortunetaly this is not working as expected. Do you have an Idea why this is the Case?
Here is the Code I am using in ChatRestrictedTaskParticipants but the query is not taken from here and the gs.info message on the beginning of the Function is also not fired:
var ChatRestrictedTaskParticipants = Class.create();
ChatRestrictedTaskParticipants.prototype = Object.extendsObject(ChatRestrictedTaskParticipantsSNC, {
getRelatedUsersCondition: function(table, sysId) {
gs.info("DEBUG-JS: override Function is uses");
var values = [];
var sourceGr = new GlideRecord(table);
if (sourceGr.get(sysId)) {
values = this.chatUtil.getUsersFromSourceRecord(sourceGr);
}
values = values.concat(this.chatUtil.getApprovers(table, sysId));
values = this.chatUtil.filterDuplicates(values);
values = this.filterUsersWithValidHRProfiles(table, values);
//This is the encoded condition to query on sys_user table
var encodedCond = 'active=true^u_samaccountnameISNOTEMPTY^sys_idIN' + values;
return encodedCond;
},
type: 'ChatRestrictedTaskParticipants'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2024 12:42 AM
Thanks again for the Hints. Unfortunately the ChatRestrictedTaskParticipants Script Include lets you only filter the Users that are selectable over the User picket ad the top:
But with the Help of my Colleagues I found now a way to filter the Users shown in the Recommended area by adjusting the "loadRecommended" Function in the "msteams_communication_swarm" UI Page.
To adchive this I only needed to add the condition "*.isValidTeamsUser == true" in the Sections adding users to the Modal. Here is an extract of the Function with comments where I made the Changes:
// Called when we get a response from the 'addLoadEvent' function
function loadRecommended(response) {
var userId = gInputData.userId;
hideLoadingIcon();
if (typeof response === 'string') {
if (response.length === 0)
return;
var result = JSON.parse(response);
if (result.error) {
// Return in case of error when fetch user details
showAlert(formatMessage(getMessage('{0}'), result.error), 'error', 10000);
return;
}
addToAvailableList(result);
var side = 'left';
for (var i = 0; i < result.length; i++) {
var item = result[i];
if (Array.isArray(item.users)) {
// add GroupName to Selected or add individual group members
if (item.showGroupName) {
addSwarmOption(result[i], side);
} else {
for (var j = 0; j < item.users.length; j++) {
if (userId != '' && item.users[j].id == userId){
addSwarmOption(item.users[j], 'right');
}
else if(item.users[j].isValidTeamsUser == true){ //added the isValidTeamsUser condition
addSwarmOption(item.users[j], side);
}
}
}
} else {
if (userId != '' && item.id == userId && item.isValidTeamsUser == true) { //added the isValidTeamsUser condition
addSwarmOption(item, 'right');
}
else if(item.isValidTeamsUser == true){ //added the isValidTeamsUser condition
addSwarmOption(item, side);
}
}
}
}
// get and save the selected values on the right of the slush bucket
var array = chatSwarmSlush.getValues(chatSwarmSlush.getRightSelect());
var r = array.join(",");
chatSwarmSlush.saveRightValues(r);
setModalParentHeight();
}
With this I could finally achieve that the Recommended Users in the left of the Modal are only Users with a MS Teams Account
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 04:17 AM