1

I have created simple ".aspx" content page, and added this page as a Tab in "Microsoft Teams". I want to get the "SharePoint Url" of Microsoft Team where content page added as Tab. To do this I need "microsoftteams.context" object. Please let me know how to resolve this problem. I tried below code (with microsoft teams JS library) but its not working.

microsoftTeams.initialize();
microsoftTeams.getContext(function(Context) {
 alert("getcontext call back function");
 alert(Context.teamName);
});

microsoftTeams.initialize();
microsoftTeams.getContext(function(Context) {
 alert("getcontext call back function");
 alert(Context.teamName);
});
Pradeep
  • 11
  • 3

1 Answers1

0

Here is sample code to fetch teamSiteUrl.

<p>
    Welcome to Microsoft Teams Hello World sample app (C#)
</p>
<script src="https://statics.teams.microsoft.com/sdk/v1.4.2/js/MicrosoftTeams.min.js"></script>
<script>
    microsoftTeams.initialize();
    microsoftTeams.getContext(function (context) {
        alert(context.teamSiteUrl);
        //teamSiteUrl will give you sharepoint url of the team.
    });
</script>

Please give it a try and let us know if you are facing any issue.

Trinetra-MSFT
  • 957
  • 5
  • 9
  • I already tried this it doesn't work. Please find screenshot, after code executes it just shows "undefined", and there is no alert.I have tried this code in developer tool of Microsoft teams. – Pradeep Jul 22 '19 at 15:06
  • I know how to get SharePointURL, once teams context object is present. But I am not able to get teams context. – Pradeep Jul 22 '19 at 15:13
  • Could you please share your content page code Or URL which we can access and check? – Wajeed Shaikh Jul 23 '19 at 02:05
  • – Pradeep Jul 23 '19 at 07:10
  • I have downloaded "Microsoft Teams" library code in my local, and referring from that location. – Pradeep Jul 23 '19 at 07:11
  • Thanks for providing code will try your code and let you know. – Trinetra-MSFT Jul 23 '19 at 09:48
  • 1
    We tried you code and able to get the teamSiteUrl, please try with latest JavaScript sdk for Microsoft Teams here is the link [MicrosoftTeams](https://statics.teams.microsoft.com/sdk/v1.4.2/js/MicrosoftTeams.min.js) – Trinetra-MSFT Jul 23 '19 at 10:16