Automating Navigation Inheritance for SharePoint Sites

Automating site creation processes with SharePoint workflow has cropped up a lot in this blog over the years. The latest battle has been getting newly-created subsites to inherit the top link navigation bar from the site collection root.

In summary...

At the time of writing, you can't switch on navigation inheritance using the REST API. I've tried, exhaustively. Google agrees.

You can switch it on using client-side code (managed client or JavaScript)... but that's no use for applications such as workflow where you're limited to code-free solutions.

However...  if you can do it with client-side code, you can do it by calling the client.svc service with an XML body. It's ugly but effective. Your web service call should look something like this:

Endpoint:
{Web URL}/_vti_bin/client.svc/ProcessQuery

HTTP method:
POST

Headers:
Content-Type: text/xml

Body:
<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName=".NET Library" 
xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009">
  <Actions>
    <SetProperty Id="1" ObjectPathId="2" Name="UseShared">
      <Parameter Type="Boolean">true</Parameter>
    </SetProperty>
  </Actions>
  <ObjectPaths>
    <Property Id="2" ParentId="3" Name="Navigation" />
    <Identity Id="3" Name="{0}:site:{1}:web:{2}" />
  </ObjectPaths>
</Request>

There are three string placeholders in the XML body above:

  • {0} is the ID of the SPObjectFactory class. At the time of writing, for SharePoint Online at least, this appears to be af552f9e-a032-4000-c7e1-e6a34cfee284|740c6a0b-85e2-48a0-a494-e0f1759d4aa7. It should always be the same, as far as I know - it's currently working for me in two different Office 365 tenancies.
  • {1} is the GUID of your site collection.
  • {2} is the GUID of the web that you want to update.
And that's it. 

(By the way, if you want to see how to bundle it all up into a custom workflow activity, take a look at this post from 2014. Visual Studio workflow activities remain the same now as they were then.)

Comments

Popular posts from this blog

Server-side activities have been updated

The target principal name is incorrect. Cannot generate SSPI context.

Getting and Setting Managed Metadata Fields in SharePoint 2013 Workflows