Showing posts from 2016

Controlling start options for SharePoint workflows in Visual Studio

When you build a reusable SharePoint workflow, it's useful to be able to control which start options are available. For example, if you only want your workflow to run once when an item is created, it makes sense to disable the "Changing an item will start this workflow" option. SharePoint Designer provides some handy checkboxes that you can use to control your start options: However, it's not immediately obvious how you can set these options for a Visual Studio workflow as the options aren't documented anywhere. To control the start options for a SharePoint workflow in Visual Studio, you need to edit the feature element file that deploys your workflow. Within the feature element file, you need to add properties to the File element that deploys your Workflow.xaml file: <? xml version = " 1.0 " encoding = " utf-8 " ?> < Elements xmlns = " " >   < Modu

Applying a Logo to Every Site in SharePoint Online

A quick post today on a fairly common problem - you're given a site collection on Office 365 that has grown organically with hundreds of nested sites, four or five levels deep in places. The various site owners have used many different versions of your company logo, and you want to reintroduce a degree of consistency by applying the same logo to every site in a site collection. The most efficient way to do this is to run some client-side code from PowerShell. Basically you need to iterate over the subsites of a given site and set the Web.SiteLogoUrl property on every site. The easiest way to do this is to: Install the excellent SharePointPnP.PowerShell cmdlets . Run a script something like the one below. # UpdateSiteLogos.ps1 # Jason Lee 5/12/16 # Variables $rootSiteUrl = "https://[tenant][path]" $credentialManagerLabel = "adminface" $logoUrl = "/sites/[path]/SiteAssets/smile.png" # Recursive functi

Get the Current User's Manager in JavaScript

Using the JavaScript Object Model to look up the manager of the current user (from the User Profile Service) seems to be a fairly common requirement - I've had to do it at least three times in the last couple of months. First of all, you need to load the profile properties for the current user: var context, userProperties; v ar stage1 = function() {      context = SP.ClientContext.get_current();      var peopleManager = new SP.UserProfiles.PeopleManager(context);      userProperties = peopleManager.getMyProperties();      context.load(userProperties);      context.executeQueryAsync(stage2, onQueryFail); } Then you can retrieve the value of the Manager property as follows: var stage2 = function() {     var manager =           userProperties.get_userProfileProperties()["Manager"]; } And that's it. Easy once you know how. Incidentally, the trickiest part of all this can be getting the SharePoint script files to load in the right order. You can't run yo

Adding Site Columns to Lists and List Views using the JavaScript Object Model

A couple of years ago, I posted on how to create SharePoint site columns using JavaScript . More recently, we needed to add a site column to a list in SharePoint Online as part of a scripted provisioning exercise. There were a few aspects of this that took a bit of trial and error, such as: Retrieving the site column from the root site. Getting the field to show up on the default list view. Hiding the field from various forms. So I figured it's probably worth sharing the end-to-end code (sanitised and simplified). First of all, let's create a site column named JasonNotes on the root site in the site collection: var context;  var rootWeb;  var rootWebId = "..."; // The GUID identifier for the root web var stage1 = function () {                context = new SP.ClientContext();            // Get the fields collection for the root web            var rootWeb = context.get_site().openWebById(rootWebId);       var fields = rootWeb.get_fields();