Microsoft Teams tab using SharePoint Framework always interact with SharePoint Online root site

Copper Contributor

Hello Everyone,

I need to create an SPFx web part that supports SharePoint Online as well as Teams

So, I have created the SPFx web part to generate the app package, and added that app package to SharePoint online as suggested below links,

https://learn.microsoft.com/en-us/samples/officedev/microsoft-teams-samples/officedev-microsoft-team... 

https://siddharthvaghasia.com/2019/06/09/adding-spfx-webpart-to-microsoft-team-tab/ 

The SPFx Teams Tab deployed successfully in the Team, But the associated lists are created under the root site. Can I change the destination of the list from the root site to another site?

Thanks

3 Replies

@BhoomeshJoshi 

Please try the following, you can change the destination of the list from the root site to another site. The Lists app in Teams is based on SharePoint and Lists data is stored in the SharePoint Online team site.

To change the destination of the list, you would need to modify the SharePoint Framework (SPFx) web part code to point to the desired SharePoint site. This can be done by changing the site URL in the code where you are creating or accessing the list.

Here's a basic example of how you might access a list on a different site using the SharePoint Framework:

let web = new Web("https://YOUR_TENANT_NAME.sharepoint.com/sites/YOUR_SITE_NAME");
let list = web.lists.getByTitle("Your List Name");

In this example, replace "https://YOUR_TENANT_NAME.sharepoint.com/sites/YOUR_SITE_NAME" with the URL of the site where you want the list to be created, and replace "Your List Name" with the name of your list.

Please note that the user must have the necessary permissions to create or access lists on the specified site.

For more information on data residency for SharePoint Online and OneDrive for Business, you can refer to this link: Data Residency for SharePoint Online and OneDrive for Business.

Also, for more details on how to use the SharePoint Framework in Teams, you can refer to this link: How to use the SharePoint Framework in Teams.

@Meghana-MSFT - Thanks for the quick response. With the above approach, I need to hard-code the SharePoint Site URL. Is there any other way to achieve the same without adding any fixed URL? Because there are multiple users who are using my SPFx web part. If I hard code the URL then it will be for a specific site only. So, I need som dynamic way to set the URL based on the user site. Thanks