Post SharePoint updates to Microsoft Teams using Flow

In this post, we will look into how to post the SharePoint updates to Microsoft Teams using Flow. Currently Flow works only on the Office 365 platform. For the SharePoint on-premises, we need to use the alternate like SharePoint designer workflow, that's another topic for another day.

For this post we will post the custom list updates to teams channel, that is whenever a new item is added we will post an update that the new item is added along with its title. Lets get started with the Microsoft Teams,

Create Connector

As a first step we need to create a connector for the teams channel. Go to your favorite channel in teams where you want to post the SharePoint updates
Click on the ellipsis (...) and then select connectors.

Add an incoming WebHook connector, and provide the title for your connector. If you have image which you prefer to show in teams whenever a message is posted then upload that image here. I prefer to use the default image for this exercise.

Once you hit save, copy the url of the WebHook which we will use in our Flow to post the message.

Microsoft Flow

Lets get into creating the flow, go to and click on My Flows. Let's choose create from blank. Give a desired title for the flow, I'm giving it "SharePoint to Microsoft Teams".

Next, go ahead and search for triggers. In this case search for SharePoint and select "SharePoint - when item is added". You need to provide the SharePoint site url and then select the list from the drop-down for which we will be posting the messages.

Click on next step and select add an action, in this step we will be using "HTTP" action, search for http and select the action. You need to select Post as method, and in the Uri field put the url we copied from incoming Web-Hook connector. In the headers, set the content type as 
{   "Content-Type": "application/json" }

In the body of the request, { "title", "New item added in SharePoint list", "text", "<<List item title>>"} in the text field I have used the dynamic content from the list. You can change the body as desired. 

Click on create and then done.

Create an Item in SharePoint list

Lets go ahead and test our flow, go the SharePoint list which selected in the flow creation process and create an item. Give a minute and check the flow you should be able to see the action successfully executed.

Microsoft Teams Channel

If everything goes well, we should be able to see the post in the Microsoft team's channel where we configured the Web-Hook connector.

That's it we have create a flow which posts updates to the channel whenever an item is created in SharePoint, we can change the action as desired for document add, update and other actions of SharePoint as well. 


Microsoft Teams FAQ on associating existing Office 365 groups

Can I associate my existing Office 365 groups to teams?
Yes, if you are owner of that group. When creating team use "add Microsoft Teams Functionality" link and select your existing group.
Why I'm not seeing my existing files from group under Files tab in teams?
In teams, the tabs are specific to the channels. Every team has a default channel "General" and there will be subsequent folder created inside the groups site documents library. If you want your files to show then move your files to that appropriate folder.

Why my existing group OneNote contents are not showing in the Notes tab?
Similar to the files, each channel has got a dedicated section. Teams only shows the pages in that particular section for the channel. If you have existing pages created before associating with teams, then move those pages to corresponding section created for channels, then it should start showing in the Notes tab.

Where is my existing group planner in teams?
As of now there is no option to add the existing planner instance to the teams, new planner instance is created when you try add one to the channel.

Get Url parameter value in SharePoint calculated column

In this post, we will try to retrieve the query string parameter value from the url using the SharePoint calculated column. In the below formula I'm trying to read the value of the query string "DefaultView". So when using the formula, I have used "11" as index which is the length of "DefaultView", that needs to changed as per your parameter's length.

Server error: Server is more recent than the version of SharePoint Designer


When you try to open the SharePoint online site using the SharePoint Designer 2013, sometimes you might encounter the below error.

Server error: The version of Microsoft SharePoint Foundation running on the server is more recent than the version of SharePoint Designer that you are using. You need a more recent version of SharePoint Designer


In order to fix it go to ,
File >> Account >> User Information >> Sign out and login again and restart the SharePoint designer.

Dynamically Changing Content Search/Search Results WebPart's Query template

This is going to be a rather a small post, on how to change the query template for the content search webpart and Search results dynamically through javascript.

The above code is more self explanatory, this approach works for both Content Search and Search Results WebPart. You can use like below to identify whether its a Content Search or Search Results WebPart
if (this.displays[0] instanceof Srch.ContentBySearch)
if (this.displays[0] instanceof Srch.Result)
Download the complete code snippet!
You can download the complete code from above link, which I have used here. Add it to the Content Editor/Script Editor WebPart. Happy coding! Peace!!

Create Image Renditions using CSOM

DOWNLOAD: Complete script can be downloaded from here

We frequently use Image renditions, in our publishing sites. In this post let see how to create one using the client side object model. We will be using SetRenditions API which takes RenditionCollection and client context. The below script shows how to invoke the API.

How to use the cmdlet

.\Add-Rendition.ps1 -Url -Title MyNewRendition -Width 240 -Height 280

DOWNLOAD: Complete script can be downloaded from here

Azure WebJobs for Office 365 SharePoint Online

As part of the on-premises customizations, we develop SharePoint timer jobs for any operations which needs to be done on a regular interval. The Timer jobs are packaged as part of our full trust solutions. In Office 365 SharePoint Online full trust code are not supported, and there is no option for us to deploy our full trust custom solutions. So there is a need to look for alternate for these timer jobs which makes use of CSOM/REST client site APIs for accessing the SharePoint resources.
As of now we have two options,
  1. Azure WebJobs 
  2. On-Premises Windows scheduled tasks 

 In this post, we will look into the Azure WebJobs option for performing any Office 365 SharePoint Online operations. For this particular case I'll be using PowerShell CSOM.
Use case: Add a new item to SharePoint custom list in Office 365 site on a regular interval. 


It's a very simple PowerShell CSOM used to create a list item, and its writes the current time as value to the title field. For simplicity I'll be creating user context based on the passed username and password. You can also create the addin-only (App-only) context by using the client ID and client secret. As said earlier, trying to keep it simple here.
Key things to note here, we are using the SharePoint Client SDK in our script. We need to make sure that to reference it from the local folder and also while packaging we need to package the PowerShell script and referenced dlls in the same folder. One more thing, we will be using "Write-Output" cmdlet in order to write anything back, "Write-Host" won't work here. 

Download: Complete zip file can be downloaded from here

Create Azure Web App

Follow the steps detailed in the video, to the create the Azure Web App, and follow the below steps for create WebJob. Open your WebApp from the Azure dashboard and in the settings, select the WebJobs. In the WebJobs blade, click on the add icon to create a new one. Give a name to your WebJob and in the "How to Run" drop down, select "continuos" for any scheduled job and "on demand" for running the job on demand. You can determine whether you want to run multiple instance in your app service or single instance. Now its the time to upload our package. Zip the folder where we have kept our PowerShell script and referenced dlls. Upload that zip file in the file upload section of the WebJob and hit create. Voila we have successfully create our WebJob. Now its the time to test the job, right click on our job from the list of WebJobs for the WebApp and click Run.

Once you hit the run, you should be able to see the status of the job status to "Running" and changes to "Completed". We can access the logs by clicking on the logs url.

In the WebJobs logs, you'll be able to see the system status like "Initializing", "Running" and finally to "Success".
Along with it there is also the information which wrote about the status of the script using the "Write-Output" cmdlet. By this way we can log any script exceptions also. In this script, shows the information about connecting the SharePoint Web and successfully creating an item inside the list.

Lets log in to the SharePoint site, mentioned in the script You can see the list item, successfully created in the list with the timestamp as its title.

While creating the WebJob we manually uploaded the package, let's also know how we do some continuos build and deployment. For the Azure WebApp, we have several deployment options like publishing using the Visual Studio publishing profile, which you can directly download from the WebApp settings and use. We also have the FTP portal access to connect by using the deployment credentials. I'm a big fan of Git, so I'm going to use Git as the deployment source.

Lets go back to the WebApp in the Azure portal and in the settings blade under the "Publishing" section. Select the deployment source and in the deployment source options select the local git repository which provisions the repository for this WebApp. Go to the deployment credentials section and create a username and password. Once the deployment source is created, you should have your git repository url, clone the repo and start pushing the changes using the credentials we created earlier. Once the repo is cloned locally, the folder structure should like below.

That's how we create WebJob in Azure WebApp and configure the job to connect to SharePoint and perform operations over the SharePoint resources using CSOM or REST.

Happy coding ! Peace !!

Export selected items to excel - Office 365/NodeJS version

Sometime back, I wrote a full trust code to export selected items to excel. It was written in the form of custom action in ribbon and a layouts application page which handles the actual excel file creation and providing it as response. The layouts application page actually uses server side APIs in order to read the list item values. It works perfectly fine for the SharePoint 2010 and 2013 on-premises instances, now it has become kind of old-school method. Office 365 or SharePoint/Office 365-D model does not support any full trust code customization, so I decided to re-write this in a addin-model utilizing the client side REST APIs. When I started thinking about the addin-model, I found two available options for replacing the layouts application page. First, replace with a traditional way of using ASPX page residing in a provider hosted addin, the only difference between the earlier version and this model will be the server side APIs will be replaced by the REST APIs. I know its quiet achievable, and no big deal. Second option is to use NodeJS instead of IIS server, and use the JavaScript with the REST APIs. So this post is about the second option.

If your are Git person, directly fork or contribute from here.

Lets directly get into action and see how it works,


Custom action 

Use the below PowerShell CSOM script to add the custom action to your list, watch out for the hard coded url used in the form submit, you need replace it with your address of your nodeJS server.  

Addin Registration

In Azure portal, register your application and give read access on SharePoint sites. Note down the client ID and client secret. For more details on registering the application in Azure AD, refer this article.

NodeJS configurations

Update the below details in the parameters.json

Install node dependencies

  1. "adal-node": ">= 0.1.17"
  2. "express": "4.13"
  3. "connect-logger": "0.x"
  4. "cookie-parser": "1.4"
  5. "cookie-session": "2.x"
  6. "msexcel-builder": "0.0.2"
  7. "unirest": "2.14.x"
  8. "body-parser": "2.14.x"


  • Run the main.js in node to start the server. 
  • Your node instance is ready and starts listening the port configured. 
  • Go to your SharePoint Online site where the custom action has been added, and select few items in the list and select "export to excel' from the ribbon
  • An excel file will be downloaded with the file name same as your list name with the selected items as rows 
Peace! Happy Coding.

OfficeDev/PnP PowerShell CmdLets - Add custom user action

In my previous post, showed how to add custom user action through PowerShell CSOM. I have re-written the same script in a new school method using the OfficeDev/PnP-PowerShell cmdlets. As a pre-requisite make sure to install the cmdlets through the binaries available in the GitHub repository. For On-Premises install v15 version and v16 version for Office 365. Post installing, use the below snippet in PowerShell window.

Happy coding! Peace!!

PowerShell CSOM - Add custom user action

There are multiple approaches to add custom user action to your Office 365 SharePoint site In this post I'm using the Powershell CSOM, and will be creating a simple custom action to show in ribbon control for custom list template. The ribbon control custom action on click will show an alert with the number of items in the custom list. First, we'll start with adding DLL references for the SharePoint Client, which will help with the remote API calls.
Next, lets get started with creating the client context and getting the existing user custom actions. Also check if the custom action already exists, and delete if already available. Lets initialize the properties for the new custom action, make sure that in CommandUIExtension the quotesare escaped properly. Also exercise care with the line breaks, when you are adding a complex JavaScript inside that block. If not it may prove costly later. Lets put altogether, when executed you'll be prompted for web site url, username and password. Provide the web site where the custom action as to be added. To validate go to any custom list and in the ribbon click "Get Items Count" button, you'll prompted with number of items in that list. Happy coding! Peace!!