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

Error

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

Fix

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 https://somesite.sharepoint.com/sites/rajesh -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. 

Code

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.

Download

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

Lets directly get into action and see how it works,

Configurations

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"

Execution

  • 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!!

Localizing in SharePoint Add-in with JavaScript


Let's consider a scenario of an Add-in development, it can be either SharePoint hosted or provider hosted. If we are looking for a localization, there are couple of approaches. If you are writing more ASP.net based add-in driven by code behind then resource files comes handy. This is more an old-school type, we have been doing this over decades and I not going to detail anything on this. More details can be found here - https://msdn.microsoft.com/en-us/library/office/fp179919.aspx. Approaches detailed on this article also includes JavaScript based one, I have tweaked this approach in a more reusable format. OK let's get into the action.

How to use it?

  • Add localizer JS to your web page
  • Create JS resource files in the file name format resource.<<ll-CC>>.js, sample resource file has been shared below
  • Add the attribute localeval="<<ResourceString>>" to the DOM elements, like <h1 localeval="HeaderText"></h1>
  • Use localizer.Init() method

How it works?

User identifies the string literals which are to be MUI and adds localeval attribute to the element with string identifier as the value. Individual resource files are created for all supported languages, and contains actual content in that language against the identifier as a set of array items. Sample resource file is given below. Localizer JS queries through the elements with the localeval element and matches the content based on the string identifier and appends the content to that element. Localizer JS selects the resource file based on the SPLanguage query string passed by the add-in as part of the standard tokens. Make sure that {StandardTokens} parameter added in the add-in app-manifest. By default "en-US" is will be set as language if the resource file is missing. The default language can be overwritten by passing the defaulLang parameter in the <<ll-CC>> format. Resource JS file is getting loaded dynamically and also getting cached for by default, set cache: false to override caching.

Sample resource file

Code Repo

It's a open source project available in GitHub, feel free to fork, star it, raise pull/merge requests and add issues. I'm happy to collaborate, Together we can make it better. https://github.com/rjesh-git/Localization

App for Testing

Also shared the sample SharePoint hosted app directly from the NAPA cloud tools, which will help to compile and deploy site if you already have an subscription. Pre-compile app can be downloaded from here for your on-premises server.

Thoughts

I have been using this approach, since the other documented approaches are quite messy around setting values for the elements from the resource file. Not a huge fan of having script tag embed between each DOM elements. Also needed a more clean pattern which can be easily reused in multiple projects. This method offers more flexibility when used along with libraries like Angular, KnockoutJS and others. There might be better option, but its a worth a choice.

Happy Coding! Peace.