how to get current team id in the newer azure-devops-extension-sdk package

1.8k views Asked by At

In the older building devops extensions examples I have found online it was possible to use VSS.getWebContext(); to get some information about the current project and selected team when creating an extension that adds a tab to the backlog area.

However there is no longer such a method with the newer SDK. So is it still possible to figure out what my current selected team is?

2

There are 2 answers

0
Matthew The Terrible On BEST ANSWER

It looks like in the context that I need to get the team ID it can actually be gotten from the new SDK.

After init if I perform the following config.team has both the team id and team name available.

const config = SDK.getConfiguration();
const teamname = config.team.name;
2
Cece Dong - MSFT On

In the new azure-devops-extension-sdk, it seems you can only get the project associated with the current page:

import * as SDK from "azure-devops-extension-sdk";
import { CommonServiceIds, IProjectPageService } from "azure-devops-extension-api";
const projectService = await SDK.getService<IProjectPageService>(CommonServiceIds.ProjectPageService);
const project = await projectService.getProject();

If your extension needs to provide users a way to select a team, you can use the Teams REST API to get a list of teams for the current project. Here is an example of how to call this API from your extension:

VSS.require(["VSS/Service", "TFS/Core/RestClient"],
   function(VSS_Service, Tfs_Core_WebApi) {
      var client = VSS_Service.getCollectionClient(Tfs_Core_WebApi.CoreHttpClient4);
  
      client.getTeams(VSS.getWebContext().project.id).then(
         function(teams) {
            console.log(teams);
         }
      );
});

For an example of an extension that provides a team picker control, see Team Calendar.