Sunday, 30 December 2018

SharePoint Designer Workflow

Automation in SharePoint

I always prefer PowerShell to do automation which is simple in few lines. Many want No Code Solutions and hence I am writing the problems in SharePoint Designer/Flow here:

Once you get used to SPD, it might be OK. If you are new, the following tips might help:

1. Always start the workflow by creating workflow variables

Here are some default variables which one might use often.

Server Relative Url - /sites/dev/aa.txt

Workflow Context-Site Url

Current Item - Name(forms) File Name with Extension aa.txt


Cannot assign empty string
Create a Trim function with "  " and assign to empty variable

Use Build Dictionary to create Response Headers

In Call to Http Service, requestHeaders are available in the Properties of the Action



Friday, 28 December 2018

SharePoint CSOM Taxonomy

I completely enjoyed many scripts in Taxonomy which I might release as a eBook later.
Below is one Taxonomy code in CSOM which helps you to get the HashTags:

$taxonomySession = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($context);
$termStore = $taxonomySession.GetDefaultSiteCollectionTermStore();
$hashTerms=$termStore.HashTagsTermSet.GetAllTerms()
$Context.Load($hashTerms)
$Context.ExecuteQuery()
$hashTerms|%{Write-Host $_.Name}

Before you run the above script, ensure you are connected and downloaded the necessary dlls.Connect by changing the User and SiteURL to your values.
#Download Sharepoint online client components
#Specify tenant admin and site URL
$User = "admin@xxx.onmicrosoft.com"
$SiteURL = "https://xxx.sharepoint.com/sites/dev"
#Add references to SharePoint client assemblies
$spPath="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\"
Add-Type -Path ($spPath+"Microsoft.SharePoint.Client.dll")
Add-Type -Path ($spPath+"Microsoft.SharePoint.Client.Runtime.dll")
Add-Type -Path ($spPath+"Microsoft.SharePoint.Client.Search.dll")
Add-Type -Path ($spPath+"Microsoft.SharePoint.Client.Taxonomy.dll")
Add-Type -Path ($spPath+"Microsoft.SharePoint.Client.Publishing.dll")
Add-Type -Path ($spPath+"Microsoft.SharePoint.Client.UserProfiles.dll")
$Password = Read-Host -Prompt "Please enter your password" -AsSecureString
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
#Bind to site collection
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Context.Credentials = $Creds

Monday, 10 December 2018

Dashboards in PowerShell

PowerShell provides a very powerful Cmdlet called ConvertTo-Html to get data and show the data in a HTML page. I have worked on many projects that get some data from SharePoint and post the data in a HTML page and later show that in SharePoint.

What are the steps I used in the code:
1. Get connected to SharePoint using SharePoint Online Credentials
2. Get the sites
3. Read the data in each sites

Below is a sample dashboard that gets the Subsites in a Site and shows as a Report of sites unused in last 6 months.


Wednesday, 5 December 2018

SharePoint Files API for Microsoft Graph

SharePoint Files API for Microsoft Graph

SharePoint CSOM,REST provides wonderful ways to create,read,update and delete files/folder from a SharePoint library.

This article uses Microsoft Graph to do the CRUD operations on the Shared Documents library in a SharePoint site.

List all Document Libraries/Drives
https://graph.microsoft.com/v1.0/sites/root/drive

List Document with name Documents Document Library
https://graph.microsoft.com/v1.0/sites/root/drive?$filter name eq 'Documents'

List items in a library
https://graph.microsoft.com/v1.0/sites/root/drive/root/children

Get a particular item by ID
https://graph.microsoft.com/v1.0/sites/root/drive/items/01TNKEB3QXIEIZFXVPVJDYAAXQEGUVUMR5

Get a particular item by Path
https://graph.microsoft.com/v1.0/sites/root/drive/items/root:/FileName.txt

Create a Folder
POST request
Path:https://graph.microsoft.com/v1.0/sites/{siteid}/root/children
Data:{
  "name": "sample2",
  "folder": { },
  "@microsoft.graph.conflictBehavior": "rename"
}





Latest REST in SharePoint for Sites from Microsoft Graph


 




Latest REST in SharePoint for Sites from Microsoft Graph

 
REST programming in SharePoint is very simple. Latest REST way of programming has been shared by Microsoft for SharePoint through Graph API.Microsoft Graph APIs are a rich source of APIs for accessing various resources of Office365 like SharePoint, Users, Onedrive. We will focus on SharePoint here.
Why use Graph API in SharePoint?
  • Letting developers develop from other platforms like iOS and Android
  • Like AI coding. Intelligent access from different sources
  • RESTful. Latest REST.
  • Any programming language
Precautions:
Use in production is not supported due to drastic changes. Sometimes, the results were not working in v1 and I had to change to beta version.
However, I started seeing real SharePoint projects using Graph API while freelancing and predicting that this will be a good and easy way to program in future soon by all.
We will look at how to construct a REST Url for Graph for SharePoint site.
https://graph.microsoft.com/{version}/{Resource}/{ODATA}
  • https://graph.Microsoft.com
  • /version
    • v1
    • beta
  • Resource
    • Site
    • List
  • ODATA
    • Select
    • Filter
    • expand

SharePoint Site Queries

Login to Graph Explorer from the link https://developer.microsoft.com/en-us/graph/graph-explorer 
Type the query and click Run Query.





Below are some sample site Queries
  • Search for sites
    • https://graph.microsoft.com/v1.0/sites?search=*
  • Get Site ID. The Site ID contains hostname,SiteCollection ID and the Web ID
    • xxx.sharepoint.com,bd041326-835c-4013-ae95-b57b4fcd0484,f6d916a3-27e1-449f-addf-82e750661823
  • Read Site By ID
    • https://graph.microsoft.com/beta/sites/xxx.sharepoint.com,bd041326-835c-4013-ae95-b57b4fcd0484,f6d916a3-27e1-449f-addf-82e750661823
  • Read Site By Path
    • https://graph.microsoft.com/beta/sites/xxx.sharepoint.com:/sites/dev
  • Read Site Pages
    • https://graph.microsoft.com/beta/sites/xxx.sharepoint.com,bd041326-835c-4013-ae95-b57b4fcd0484,f6d916a3-27e1-449f-addf-82e750661823/pages

Comparison with SharePoint Rest Url

While working on old SharePoint REST, you would begin the SharePoint rest url with the site link.
Example : https://xxx.sharepoint.com/_api/web/title
Graph SharePoint
Read Sites Only Create Sites also
Root Url : https://graph.microsoft.com/beta Root Url : https://xxx.sharepoint.com/_api/web/title
Select Items ?select=Title Select Items ?select=Title
Expanding ?expand=Author Expanding ?expand=Author

Summary

You learnt how to construct SharePoint Sites URL in Microsoft Graph:
  • Read Sites by ID
  • Read Sites by Path
  • Read the Pages in a Site