Sunday 16 October 2016

SharePoint REST API $expand query option.

A few months ago, I got a task that only logged-in users can edit list items created by themselves, which requires the Created By (Author) and Modified By (Editor) field values of that list item.

So, I will share my experience in resolving it. The Created By and Modified By values doesn't appear when a GET request is done; only AuthorId and EditorId are returned, as given below.


The Created By (Author) and Modified By (Editor) fields are of the People type. If you want the Author and Editor Title values, then you have to use the REST API $expand query option. The $expand query option is used to lookup column values, or you can think of it as a JOIN on two lists like in SQL for getting data. The SharePoint REST API supports OData query options. In this scenario, the lookup column points to the User Information List to get the person's details.

The code snippet below defines the proper usage of the $expand query option in the REST API. The code expands the Author and Editor entity fields, and in the $select column name, a forward slash (/) is used.


The success response object is logged using the console API.



The below image shows all the values returned.



🚀 "Happy Coding" 🚀

CSOM PowerShell: Create Term Store Management.

In this blog article, we will create a solution to create "ManagedMetaData Terms" which can be deployed on-premise, SharePoint Online (Office 365), or hybrid platforms.

The artefacts or functionality created using server-side or client-side techniques are not compatible, so they can be used to deploy solutions on any platform.


SharePoint PowerShell is a PowerShell API for SharePoint 2010, 2013, and Online. Very useful for Office 365 and private clouds where you don't have access to the physical server.

The API uses the Managed .NET Client-Side Object Model (CSOM) of SharePoint 2013. It's a library of PowerShell scripts, and in its core, it talks to the CSOM dll's.

The basic steps to implement CSOM PowerShell are:
1) Add Microsoft.SharePoint.Client.dll, Microsoft.SharePoint.Client.Runtime.dll and Microsoft.SharePoint.Client.Taxonomy.dll assemblies (which can be found in the ISAPI folder).
2) Create a ClientContext object.
3) Call the Load() and then ExecuteQuery() method.
4) Call the get and set methods using the ClientContext object.


Prerequisites for easily implementing the CSOM PowerShell script (optional).
Download the PowerGUI Script Editor IDE, which is free from http://en.community.dell.com/techcenter/powergui
It's a very powerful IDE for PowerShell, similar to Visual Studio.
It provides various features, like
1) Script Explorer.
2) Intellisense.
3) Variables and Call Stack.
4) Debugging and many more.


Steps to be used to create Term Store Management are:
1) Add dll's, create clientcontext and load (web and site) objects, and call the executequery() method.
2) Create the ManagedMetaData function and pass the clientcontext object.
3) Which reads the "ManagedMetaData.xml" file content (saved on the local drive).
4) Call the Get-TermStoreInfo function to get all groups and load them.
5) Check whether the group already exists or not, and then create it.
6) Then call the Create-TermSet function and pass the required parameters.
7) Again, check whether TermSet already exists or not, and then create TermSet.
8) Create Terms by calling the Create-Term function.










For more information, download the source from: click here


🚀 "Happy Coding" 🚀