Sam's Microsoft Dynamics 365 Blog

Thursday, 12 December 2019

Get Context in Add-in’s of Microsoft teams

In many Business scenarios, we have to create Add-ins for Microsoft Teams. Also, we need to define the Context in this Add-in.  So, in this article, we will discuss about getting Context in Microsoft Teams’ Custom Add-In.

So, let’s discuss Step by step: -

1. I have created a HTML page and adding a script reference of MicrosoftTeams.min.js. With the help of this Script reference, we can get a Context.

2. Now I have added a Script section in my HTML Code and added code for initializing the Context, as shown below.

<p> Hello World! </p>

<script src="https://statics.teams.microsoft.com/sdk/v1.4.2/js/MicrosoftTeams.min.js" crossorigin="anonymous"></script>

<script>
var mycontext;
microsoftTeams.initialize();
microsoftTeams.getContext((context) => mycontext=(context))
console.log(mycontext)
</script>

3. Now I will deploy this code to my domain, and I will add domain URL to my Add-in JSON (manifest.json).

4. After that, I will import my Add-in Package to Microsoft Teams and then open the section where I have added this IFrame.

5. Now I can see in Console (In Chrome browser). Here it is printed a JSON of context. It will look as shown below.



Thanks for reading the article. Hope this Article will helpful for you. Cheers!!!


Web Resource vs PCF vs Canvas App - which of the one is used?

While started working on specific Business Requirements related to custom layout, there is a always common question that "where to star...