Introduction

If you’ve ever struggled to locate a specific team on Microsoft Teams, especially when you have a large number of teams that are not organized in any particular order, you know how frustrating it can be. It can be a waste of time and lead to frustration when you can’t quickly find the team or channel you need.

Unfortunately, Microsoft Teams does not currently offer any built-in way to sort teams alphabetically. However, there is a workaround that allows you to do this using a script. In this post, we’ll walk you through the steps to alphabetically organize your Microsoft Teams using a JavaScript script.

Creating the script (and this post 😇) using ChatGPT

With all the recent buzz about ChatGPT and its ability to write code, we decided to give it a try. Iteratively writing code using ChatGPT in a Q&A manner was a truly amazing experience. We didn’t have to spend any time understanding each line of code; we simply let ChatGPT generate the code for us. It was very satisfying.

We also used ChatGPT to write this blog post, which made the writing process faster and more professional. Overall, it required much less effort on our part.

Asking ChatGPT for a catchy blog post title

The script

Here is the script that will alphabetically reorder your Microsoft Teams:

// Find all "a" elements under the "team-favorite-group" element
let teamsArray = [];
document.querySelectorAll('[data-tid="team-favorite-group"] a').forEach((elem, i) => {
  // Check for the "data-team-id" and "data-tid" properties
  let dataTeamId = elem.getAttribute('data-team-id');
  let dataTid = elem.getAttribute('data-tid');
  if (dataTeamId && dataTid) {
    teamsArray.push({
      order: i,
      teamId: dataTeamId,
      dataTid: dataTid,
    });
  }
});

// Sort the teamsArray list based on the value of data-tid
teamsArray.sort((a, b) => a.dataTid.localeCompare(b.dataTid));

// Set the correct order for each team
teamsArray.forEach((team, i) => {
  team.order = i;
  delete team.dataTid;
});

// Build the result in the required JSON structure
let teamsOrder = {
  teamsOrder: JSON.stringify(teamsArray),
};

// Get the skypetoken_asm cookie value
let skypetokenAsm = getCookie('skypetoken_asm');

// Make a PUT call to the specified URL with the teamsOrder object as the body
fetch('https://emea.ng.msg.teams.microsoft.com/v1/users/ME/properties?name=teamsOrder', {
  method: 'PUT',
  body: JSON.stringify(teamsOrder),
  headers: {
    'Content-Type': 'application/json',
    'Authentication': `skypetoken=${skypetokenAsm}`,
  },
})
  .then((response) => {
    console.log(response);
  })
  .catch((error) => {
    console.error(error);
  });

// Function to get the value of a cookie
function getCookie(name) {
  let value = `; ${document.cookie}`;
  let parts = value.split(`; ${name}=`);
  if (parts.length === 2) {
    return parts.pop().split(';').shift();
  }
}

How to run the script?

To alphabetically sort your Microsoft Teams, follow these steps:

  1. Navigate to the web version of Microsoft teams: https://teams.microsoft.com.
  2. Open your browser developer tools (see here for instructions on how to do this: https://updraftplus.com/faqs/how-do-i-open-my-browsers-developer-tools/)
  3. Copy the script provided in the previous section and paste it into the console window. Then press “Run”.
  4. Refresh your browser and your teams should now be sorted alphabetically.

⚠️ Please note that this method is not officially supported by Microsoft or the author of this script. Use it at your own risk.

Conclusion

In conclusion, while Microsoft Teams does not currently provide a built-in way to sort teams alphabetically, it is possible to do so using a script. This can be helpful for organizing and structuring your teams in a logical, easy-to-navigate manner. However, please be aware that this method is not officially supported by Microsoft and may break if Microsoft makes changes to the Teams front-end. Use it at your own risk and consider voting for the addition of an alphabetical sorting feature on the Microsoft Teams Feedback Portal: https://feedbackportal.microsoft.com/feedback/idea/7c16f408-272e-ec11-b6e6-00224827bbc2.

4 thoughts on “Alphabetically organize your Microsoft Teams with the help of ChatGPT”

  1. Wow! First of all thank you for your time and this post, very useful!
    I runned it in Edge (default Windows browser) and the first time it did like a “half” attempt, but second time it worked! THANK YOU!

  2. Hello, I added this script and it worked perfectly. It was curious to see how it worked and need to remove it. I am not able to figure this out. Can you help?

Leave a Reply