2

With SPFx 1.7 preview release, I know we can access Teams Context information in SharePoint Framework web part but not from SharePoint Framework extensions. I looked at ApplicationCustomizerContext class but didn't find any reference. Wondering if Teams context information is available in SharePoint Framework extensions?

1 Answer 1

4

Interestingly I found the way to get Teams Context information in SPFx extension. Follow the below steps to do it:

  1. Do "npm install @microsoft/teams-js --save" in your SPFx extension project.

  2. In your .ts file or if you using React, then inside your target component, import microsoftTeams names as 'Import * as microsoftTeams from '@microsoft/teams-js'.

  3. In your code, use below code:

        try {
            microsoftTeams.initialize();
            microsoftTeams.getContext(tContext => {
                console.log('Inside Teams:'+tContext.teamName);
                this.setState({ ShowBanner: false });
            });
    
        } catch (error) {
            console.error("Exception while getting Teams context:" + error);
        }
    
2
  • Amazing, thanks for this :D
    – BennKingy
    Commented Jan 14, 2021 at 10:44
  • is this correct way ? . however code is working
    – DevÁsith
    Commented May 21, 2021 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.