This blog is about SharePoint, Office365 and Office Development

Popular Posts

New Document Library Experience : Part II Custom Actions


In my pervious post I explained the newly introduced experience with a deep dive explaining the various building blocks of the page. In this post, I will focus more on one particular action which is  the custom action, and how it has been affected by the new experience.

Custom Action Navigation Action

Custom actions are handled using "odsp-next/actions/odb/CustomActionNavigationAction" module. In this module, a simple check to UrlAction property value is done. The decision is solely based on whether it starts with the string "javasctipt:"  or not . In the first case, a call to executeCustomActionJSCode function will be performed. However, in the second case(when you simply register UrlAction as a simple link) new window will open and navigate to the desired web address.



Note:When you register your custom action using visual studio , the custom action ActionUrl property will be converted to Javascript:LunchApp(yourUrl,popup options)

popup options will always be null unless you use dialog width and height parameters in the custom action definition in Visual Studio elements.xml File. If the popup options parameter is not null, a  Javascript error will be thrown. To reproduce this simply try any custom action with dialog parameters , deploy it to SharePoint library as ECB or ribbon button.


Before execute javascript code block window.RegisterSod is called for alot of SharePoint files which used to be included/registered via masterpage

Any ScriptLink Globally registered script is no longer executed in the new experience pages like document library/site contents.

Url Token Replacement

Another important notice that not all the tokens within the ActionUrl will be replaced, only the following token will be replaced if you are using the new SharePoint library experience.
  1. {ItemId}
  2. {ListId}
  3. {Source}
  4. {SiteUrl}
  5. {ItemUrl}
  6. {SelectedItemId}
  7. {ListUrlDir} 

What to expect next:

Currently all the customization opens the classical SharePoint dialog doesn't work in the new document library experience, it will be nice if Microsoft release the new extensibility framework which will eventually replace the old dialog with the ability to create your own action handlers,components and executors similar to rename out of the box actions:

RenameActionHandler

RenameActionExecutor




New Document Library experience: deep dive Part I



Recently the new SharePoint document library experience has been released, you probably have already seen it if your tenant is on First Release.

Exactly one week ago Stefan Bauer published a very insightful blog post focusing on the main building blocks of the new SharePoint document library experience.

Although I have no previous experience with either ReactJS or knockoutJS I decided to give it a try and attempt to figure out the building blocks in more details:

Let's have a look on the Files 

I won't write any details around the framework used as Stefan covers it brilliantly in his blog in addition to the main pillars (RequireJS , React, Knockout JS), you can find bundled and minified version of files delivered via akamaihd.net CDN with the subdomain spoprod-a (SharePoint Online Production) can't really figure out the "-a" part of the subdomain name.



Note: facebook use the same CDN as well.

After a quick look at the HTML elements, I can see several components within the page, when you trace it down you have two main components ms-spo-app and ms-files

ms-file contains around 14 child components:

  • ms-suite-nav                       (top navigation component)
  • ms-left-pane                       (left navigation component)
  • ms-search                           (search)
  • od-userFeedback                (feedback link)
  • ms-drag-and-drop               (enabling drag and drop files)
  • od-overlay-host                   (container for the ECB Item menu) 
  • od-dialog-host                     (container for dialogs like rename dialog)
  • ms-panel-host
  • ms-hidden-dom-host
  • od-transclusion-host          ( info right panel)
  • ms-standalone-list              (This is the main component for the list
  • ms-command-bar               (list commands "ribbon replacement")
  • ms-siteHeaderKOHost


In this blog i will focus on one component , so let's take a look at the new right info

The new Info Panel


If you click on the info icon to the right you can see recent activities and number of documents in the current view. However if you do select a specific file you can see file preview and number of sections:

Overview Section

This section always appear. However, it appears in two different renditions if the document is selected an iframe will be rendered to review the document using wopiFrame.aspx page.

Other sections 

The other sections:
Recent Activity, Properties, Sharing, Information will appear based on collection calculated by function called availableSections()

here is function execution in case of  no file is been selected ,we notice that it's only single section with a component named "ms-activities-feed"



and if a single file is been selected, more sections appears in the availableSections call to render 
document edit form , sharing and infomation




What happens when you change item selection 

When the user select a document and the right information panel is active, series of network activities is fired up to get the data necessary to render the right information panel



File Sharing Settings

Two different calls to  2 different point to gather sharing information 



File Properties

A single request to RenderExtendedListFormData which  passes the following parameters:
  • Item Id  
  • form Id  : string representation of the form 'edit form'
  • mode 
  • options 

I couldn't figure out either the mode or the options yet

In the next part I will talk more about different actions which can be found in file https://spoprod-a.akamaihd.net/files/odsp-next-prod_ship-2016-07-11_20160715.004/splistdeferred.js:

and I will focus on one particular action odsp-next/actions/odb/CustomActionNavigationAction which handles the execution of UrlAction custom action and how the new document library experience affects (at the moment) any existing document library based customization.


OfficeDev: Building CrossPlatform SharePoint Custom Action using NodeJS


This post is a part of a series focused in building SharePoint extensions using NodeJS, the aim of this series is to provide a guide on how to build cross platform SharePoint solutions. In case of Office Add-ins office generator makes it very easy for us to build cross platform Office Add-ins. However, to extend SharePoint contextual add-ins we were always stuck with Visual studio or using Napa and build SharePoint hosted apps.

In this post I will explain how to build and deploy  a NodeJS Provider-hosted app with Custom Action that updates the Item Title.

The Add-in will consist of Three Major parts



App Principle



For simplicity I will focus on apps with apponly mode switched on, to get a new app principle simply navigate to  https://yourtenantname.sharepoint.com/_layouts/AppRegNew and generate  new App Id and secret.

In my case I will deploy the custom action to a new azure website called "o365-customaction"  so I've added o365-customaction.azurewebsites.net as my "app domain"

In the permission textbox I've added the following permissions giving my app tenant full control
save your app Id and secret and move on to the next step

App Web


When using Visual Studio template this will be created for us automatically when we choose to build a provider-hosted app or once we enable or add any remote event receiver, in this case let's use yo express to scaffold a basic nodejs web app for us.
  1. Install express yo generator
  2. Create new app
  3. Let's configure handling custom action via new middleware using  
  4. Create the update item handler
  5. O365Connect.js handles getting apponly token and update the list item
  6. Deploy web app to azure 
  7. To Deploy your web app to azure you need to install azure-cli package globally for more details check my previous post at http://www.sharepointtweaks.com/2015/10/building-outlooj-add-in-using-office-yo-generator.html
  8. At this step I assume you can deploy your nodejs website to azure using azure local repository and azure-cli

Deploying SharePoint Artifacts

At this moment we have a NodeJS web application running in azure, within the context of this web app user have full control of your SharePoint Online tenant. The missing piece is to create the custom action. One quick solution is to use powershell to create the custom action however, this will defy the purpose of this post which is making SharePoint development cross-platform.

RESTful APIs to the rescue

Using the SharePoint RESTful APIs you can retrieve and update any web custom user actions using basic http request by executing GET, DELET, POST HTTP requst to the /_api/web/customactions end point

Introducing gulp-sharepoint


This is a seed for a nodejs module that can be used to deploy SharePoint artifacts as gulp task currently it used to only deploy SharePoint custom action as gulp task



Hooking it up with deploy command

by adding the following lines to deploy.cmd this will allow this task to run whenever you update the azure local git repository the current logic of adding custom action is removing any old custom action that has the same name

See it in action !


What Next?

Anything is possible, you can easily build a complete set of cross-platform CLI tools to talk to SharePoint RESTful APIs and build the app web using any technology  stack you desire.



Building an Office Assistant using botframework: v3 update

Almost couple of months ago I published a complete three part walk-through:
Part I (http://www.sharepointtweaks.com/2016/04/officedev-introducing-office365-bot.html)
PartII (http://www.sharepointtweaks.com/2016/05/officedev-introducing-office365-bot.html)
Part III (http://www.sharepointtweaks.com/2016/05/officedev-introducing-office365-botpart3.html))

The walk-through focused on building an office assistant bot using Luis.ai and botframework. However,  last weekend I received an announcement email introducing the newer version of botframework (v3), so I decided to migrate my existing Office assistant bot from the old v1 botframework to v3.

I've published a new branch to my git repository which includes a working version 3 of the same very basic meeting booking bot

you can have a look at
https://github.com/ministainer/O365-Assistant/tree/v3





OfficeDev: Inconvenient SharePoint App only permission using Azure AD Apps

App Only Permission using AAD App and SharePoint online
I was playing around with adal-node trying to build a remote event receiver using NodeJS, however I stumble on a big issue, which is even my Azure AD App explicitly has SharePoint Online added as a resource with all app only permission set selected I always got a strange error "unsupported app only token" I find out that my fellow MVP  John Liu faced a similar problem and he explained it in details in his post here with a fix using certificates.



Inspecting SharePointContext.cs


By Looking at SharePointContext.cs abstract class which is generated when you add SharePointPnPCoreOnline nuget package to your visual studio project I notice in this case app only permission works fine for SharePoint online!
By going through the code and with little help of ILSPY I manage to understand how the accesstoken is being generated using SharePointContext  and TokenHelper classes to access SharePoint online via client credentials, the flow is as below:

  1. get realm by executing dummy call to client.svc and reading the www-authenticate header 
  2. update client_id to be on the format client_id@realm
  3. update resource to be string concatenation of the following
    1. SharePoint Principle always =00000003-0000-0ff1-ce00-000000000000
    2. your tenant subdomain *.sharepoint.com
    3. realm value
  4. executing a client_credential token POST request to https://accounts.accesscontrol.windows.net/{realm}/tokens/OAuth/2

by executing this request in postman I manage to get access_token for SharePoint online 


Creating NodeJs Module

After this small experiment I figured I will create a small nodejs package so it can be used to connect to SharePoint online using client Id and secret without the need for a certificate in the same manner any command line application created using visual studio can.

I've created nodejs module and published it here @https://github.com/ministainer/SharePoint-apponly-node

The modeul is also published @https://www.npmjs.com/package/sharepoint-apponly-node you can install it by simply

and here is how to use it



The repos is just a seed will add token refresh and cache capabilities later.