An Sitecore Multilist field with an External Datasource

This week I needed to create an Multilist which required a DataSource that doesn’t reside in Sitecore.
I’ve done this a few times before but using an DataSource for a Multilist from outside of Sitecore isn’t something I have needed to do often.
There aren’t many articles on how to do this, so I thought I’d write up how to do this using Sitecore 9 (it should work with Sitecore 8 and below too).

hqdefault

I’ve based the implementation on the code from this post by Benjamin Vangansewinkel: http://sitecoreblog.blogspot.co.uk/2012/04/how-to-create-custom-multilist-field.html. So Kudos to Benjamin for writing this back in 2012. The are alternatives to this approach such as using creating a custom token or a custom data provider but I feel a custom Multilist is simpler and easier to manage.

Benjamin’s post is really useful, but some of the code is missing and I needed to show a count of the items available and selected in my Multilist. I’ve also simplified things a little bit and included the full code with an example API call to populate the list.

When it’s complete it will look like this:

multilist-external

Ok lets get started.

Create a Base Class – BaseExternalMultiList.cs

So that we can re-use this implementation for other Multilists with external DataSources we are going to create a Base Class that encapsulates the code for building the Multilist.

The class provides the method for rendering out the Multilist field and I have updated the Javascript to show a count of the number of available items and the selected items when you add or remove items from the list.

Create An Custom MultiList Field – CryptoMultilist.cs

The next Step is to Create our Multilist field by implementing the Base Class. There are 3 methods here that can be implimented:

  1. InitRendering() – in this method we will call our API and populate the list.
  2. GetNonSelectedItems() – in this method we will get our list of all available items.
  3. GetSelectedItems() – in this method we will populate our list of selected items.

Just for fun I’m using an example of a Multilist field that lists all available Crypto Currencies. I’m using this API to get the list: https://www.cryptocompare.com/api  

The API Service – CryptoService.cs

You can obviously use any Service but this example makes a simple call to get a list of Crypto Coins. There are a lot of them apparently, 2528 at time of writing!. This is not production-ready code but provides a simple example for testing. Replace this service with any other service you like to return a list of items.

Supporting Classes

There are some supporting model classes required by the above Service code that allow me to Serialize the JSON response from the API to these models. I’m using Json.Net to do this.  Depending on the API you are using you will need to update these models as required.

Once you have added the above code to your project you can then move on to configuring Sitecore to use your custom Multilist field.

Adding the Custom Multilist to Sitecore

Go to the Core database in Content Editor and navigate to:

/sitecore/system/Field types

Create a new item called ‘Crypto Multilist’ using this template:

/sitecore/templates/System/Templates/Template field type

It is best practice to create a new folder to hold your custom field types (if you don’t have one already).

Add the Assembly and Class information (based on the namespace and assembly of the files you have added). Add an icon to identify your field easier also.

core-db-multilist

 

Save your new field and then go back to the Master Database in Content editor and navigate to a template you wish to use the new Multilist field on.

Using your Multilist Field

You should now be able to add your new Multilist field to any Data template by selecting it as a Field Type from the dropdown.

add-field-template

Now when you add or edit an item using this Data Template your Multilist field should display populated with the External data and maintain the selected items when saving and going back to the item.

new-field-on-item

Thats all there is to it, you can now re-use this approach for any additional External Datasources you wish without much effort by switching out the service and models.

I might package this up and put it on NuGet at some point if it’s useful. I’d be interested to know of easier or better ways of doing this also.

 

Sitecore SUGCON 2018

Estrel
I’ve just come back from SUGCON 2018 in Berlin and I think it was the best one I’ve been to yet. It was my third time attending the Sitecore User Group Conference (a conference for the Sitecore Community organised by the Sitecore Community). This year I was lucky enough to be going as a first-time MVP and would be collecting my award during the conference.

I arrived early to see a bit of Berlin on the Sunday and catch up with some friends, colleagues and other Sitecore Devs and MVPs and before I knew it it was time for SUGCON to start.

sky

It kicked off with some fancy lights and music and Peter Brinkman with the opening Keynote explaining how large SUGCON has grown since it started in 2016, there were 600 attendees this year!.

There was a lot to take in over the 1.5 days so before I forget it all I’ve summarized below some key learning’s from my two days at SUGCON 2018.

Day 1

Opening Keynote – Pieter Brinkman

welcome

    • There will be two major Sitecore releases every 6 months and (spring & fall) which will contain new features and functionality
    • Updates / Patch releases will only contain fixes and not features/breaking changes.
    • Releases will be a full delivery including code, training and documentation

Sitecore releases

Great news for all Sitecore developers and customers who have been frustrated with this in the past.

Commerce + IoT In Powerful Ways – Jason Wilkerson & Richard Seal

Next up was well known MVPs Jason Wikerson and Richard Seal who created a fictional SitecoreLand complete with wristbands to access the park to demonstrate how IoT can be used with Sitecore .

IoT

    • Previously this was only possible by building most of the functionality yourself buy it is now possible out of the box with xConnect + and IoT Hub and IoT Listener.

IoT

  • Store the least amount of data you need to achieve what you want to do for your customers.
  • With SXA, Experience Commerce, xConnect, EXM, xDB and Marketing automation you now have all the tools you need to create these kind of experiences for customers with Sitecore. Your imagination is the only limitation.

Impressive stuff and a real show-case for what’s possible with Sitecore. Speaking to Jason afterwards he said it took longer to Photoshop in the memes of Longtime MVP Jeremy Davis who got trolled hard in the talk. This wasn’t to be the only time today either :-).

Jeremy

Uber-modern Apis For Sitecore – Kam Figy

Kam has been building the CLI for JSS and underlying APIs and took us through some of these focusing heavily on GraphQL.

graph API explorer

  • GraphQL is:
    • Strongly Typed
    • Queries only the specific fields you need (no overfetching)
    • The response matches the query (so you know what you are getting)
    • Is discover-able
    • Batches queries and catches and returns errors
  • Kam demo’ed an app he’d built that used GraphQL and mimic’s the database browser in Sitecore.

jss browser

  • It’s possible to extend the GraphQL API using Query Extenders and add additional fields. These are than patched in using config.

extender

links

All-in-all some interesting stuff to experiment with here, since I’ve playing about with JSS too this is something I plan to look at in more detail.

Sitecore XDB & GDPR Applied – Rob Habraken

gdpr

Rob opened by saying this was a dull subject. That it may be but it is also a very hot topic and something many clients need to implement very soon so this was a very insightful session for me.

sitecore gdpr

  • Sitecore 9 has GDPR features out of the box and Sitecore 8.2 Update 7  will also have them.
  • 6 Steps to follow to implement GDPR With Sitecore:

IMG_1529

IMG_1532

IMG_1536

IMG_1540

IMG_1542

IMG_1548

Azure Round Table – Tamas Varga

The final session I attended was an Azure Round Table where there were some really good insights from those who have used Sitecore Azure:

Azure

  • Using the provided Azure ARM Templates is a good start but can I can be limiting as time progresses so creating your own is the way to go eventually.
  • There can be problems with CSS and JSS not being published yet when swapping between servers.
  • Testing an Azure Sitecore setup on a development environment and keeping costs down can be a challenge. MSDN provides free credits for subscribers.
  • If using Azure the advice is to move to Sitecore 9.x if you can first as that will make things much easier.

Awards, Quiz & Drinks

At the end of Day 1 I had the privilege of going on-stage and picking up my MVP award with the other 2018 MVPs. I’d seen the MVPs collect their awards in previous years but didn’t think I’d be joining them this year, I felt very proud to be sat alongside everyone. Obviously a few beers were enjoyed afterwards to celebrate.

mvps

Day 2

Sitecore Install Extensions In Action – Robert Senktas

I hadn’t heard of SIX before but having had some experience of using SIF when installing Sitecore 9 this looked interesting.

IMG_1562

  • SIX has a number of powerful features that make it superior to SIF and it support storing sensitive data in Azure Keyvault:

IMG_1564

SIX

  • An early GUI was demo’ed that runs on top of SIX and allowed an Octopus style management of the install process.

softserve

This all looks pretty cool and definitely something I’m going to look into further.

White Hat Hackers Guide To The Internet – Mikkel Ole Romer

IMG_1576

This was the most packed break-out room I saw over the two days.  Mikkel showed some simple Hacking Techniques he’d tried on a list of Sitecore Solutions and the results were quite worrying.

  • He showed us some simple hack’s he’d tried:

IMG_1577

IMG_1580

IMG_1581

  • The results of the test were a little worrying…

IMG_1582 IMG_1584 IMG_1585This session was a bit of an eye opener to say the least. Check your Sitecore installs configuration and patches folks!

 Sitecore & The Blockchain – Jason Bert

Since I have some Bitcoin & Ripple and I’m interested in Crypto and the application of Blockchain technology this seemed like a talk I wouldn’t want to miss.

blockchain

  • Jason used a number of technologies to store the details of a ticket purchase on the Etherium Blockchain.

IMG_1594

IMG_1595

  • Jason used a local Etherium Blockchain testing tool called Ganache but in the real-world this could be slow and potentially costly.

IMG_1596

This was an interesting talk that certainly makes you think about how these technologies could be used in future.

From Forms to Riches – Kamruz Jaman & Mike Reynolds

IMG_1598

Having talked to Kam a bit about what he was going to discuss I was looking forward to a bit of a deep-dive into the new Sitecore 9 forms module and thats exactly what we got.

IMG_1600

  • The metrics stuff and interface looks pretty cool.

IMG_1602

IMG_1605 IMG_1606 IMG_1607

  • We were also shown how to create a custom field and data encryption was discussed.
  • But there is some functionality missing as it’s an first release. If you need to you could build some of this yourself.

IMG_1617

Latest Goodnesss JSS – Alex Shyba & Adam Weber

Having presented a talk on JSS at the Sitecore Sessions in Manchester recently I had a good idea about most of this talk but there was still some really great stuff to see and hear. I got to speak to Alex and Adam in person too and they were really helpful.

jss

IMG_1624

IMG_1625

Rendering level JavaScript was what I was really interested in seeing. This is JSS Components running along-side MVC ones in the same page!.

IMG_1629

It was really cool to see this in action. I’ll be trying this out as soon as I get chance.

IMG_1631

IMG_1633

IMG_1637

IMG_1640

Time to go home

After a few words of thanks to the organisers and attendees for an fantastic SUGCON it was time to head home….After a few more drinks of course.

IMG_1642

What did I get out of SUGCON?

This year I was determined to do more networking and spend time talking to people in the Sitecore Community who I’ve spoke to on-line but never/rarely met. I certainly learnt a great deal from the sessions too but getting to chat to fellow MVPs, Developers, Sitecore Employees who I’ve known online for sometime but not met was my favorite takeaway from the past couple of days. If you didn’t make it this year and are thinking of going next year then I’d highly recommend you get your tickets booked for SUGCON 2019 in London on the 4th & 5th of April. You won’t regret it.

My Sitecore MVP 2018 Journey So Far

Back in late January I was fortunate enough to be awarded Sitecore Technology MVP 2018. For anyone in the Sitecore Community this is a great privilege as there are only 208 Technology MVP’s worldwide and 20 in the UK.

Sitecore_MVP_logo_Technology_2018

I hadn’t got round to writing on my Blog about it at the time so I thought it would be good to talk about my experience so far this year as an MVP and also what my plans are for this year.

Every year, the Sitecore MVP Awards honour individuals with a passion for sharing their knowledge and expertise through active participation in online and offline Sitecore communities.

Sitecore has an fantastic community of developers who really try and help one another out both online and offline and share their knowledge and expertise whenever they can.

If you want to see the full list of Sitecore MVPs for 2018 you can see it here: https://mvp.sitecore.net/MVPs/2018

As an MVP there are a number of benefits; such as getting to give feedback to Sitecore on things they are working on, access to additional resources and Community Groups and gaining early knowledge of future releases & features coming out of Sitecore HQ.

How Do I Become an MVP?

I’ve seen this asked a few times on Twitter, Slack and Stack Exchange etc and I think the consensus is that you shouldn’t aim to become an Sitecore MVP but should instead try and get involved in the Sitecore Community as much as possible.

Share what you learn on a Blog,  get involved in Sitecore Stack Exchange (SSE) by posting both questions and answers, join in on Sitecore Slack anad get involved in your local Sitecore User Group. Maybe do a presentation or two and share your learnings and expertise.

This is a great post on SSE from Mark Cassidy with more ideas of how you can get involved in the Sitecore Community: https://sitecore.stackexchange.com/questions/1689/how-can-i-connect-with-the-sitecore-community.

By getting involved in the Community like this if you feel you’ve contributed enough you can nominate yourself (usually in November) and ask others to recommend you too.

You can read more about the MVP program here: https://mvp.sitecore.net/become-an-mvp

There is also an excellent SSE post here about becoming an MVP by Tamas Varga (who is an Technical Evangelist at Sitecore and works on the MVP Team): https://sitecore.stackexchange.com/questions/5796/how-to-become-a-sitecore-mvp

My Plans For 2018 as an MVP

Since becoming an MVP I’ve tried to continue being active in the Community and have written some useful blog posts on Installing Sitecore 9 Update 1 and Getting Started with JSS.

Part 2 of working with Sitecore JSS is coming up soon and I’ll be giving a talk on this at the next Manchester meetup along with 2 talks from other Sitecore MVPs:

The Sitecore Sessions

London, GB
226 Members

The Sitecore Sessions are a group of events, up and down the country, with an aim of catering for what we hear the community want to know more about.We have been, and contin…

Check out this Meetup Group →

 

I’m planning on giving an overview of installing JSS. I’ll then be going into more detail on and getting up and running and building components. Hopefully this will be one of a number of presentations I’ll get to do this year.

I’m also hoping to build my first Sitecore Module and share it on the Marketplace this year. I’ve got a few interesting ideas so watch this space.

I’m really looking forward to learning more about Sitecore 9 and catching up with the Sitecore Community & other Sitecore MVPs at SUGCON in Berlin next month and the MVP Summit at Symposium later this year.

Lastly I wanted to say thanks to Sitecore and the great Community for recognising my contributions and particularly the MVPs and Sitecore staff that recommended me (you know who you are :-)).

 

Getting Started with Sitecore JSS

I saw a demo of JSS at SUGCON last year by Alex Shyba and it looked really cool. Ever since I’ve been keen to try it out as soon as I could. This post covers the basics of setting up JSS and running a demo React App.
jss-logo
The first stumbling block however was getting an install of Sitecore 9 up and running.
You will need this before you can proceed with the rest of this tutorial so if you don’t have Sitecore 9 installed already then you can read my Blog Post on how to install Sitecore 9 update 1 here.

What is JSS?

JSS is an SDK that allows developers to build websites using Javascript frameworks such as React and Angular. Sitecore is used as a Headless CMS to provide the Sitecore item’s presentation details as JSON. It has full support for the Sitecore Experience Platform, including Experience Editor, Personalization, MV testing and Tracking / Analytics.

One thing that will keep front-end developers happy is that Apps can be built entirely detached from Sitecore and then deployed to Sitecore later. This also means that Sitecore doesn’t need to be installed to build applications with JSS. Apps are deployed to Sitecore using JSS code-first services via the command line.

This just touches on the basics of JSS, you can read more about it and the full install instructions here: https://jss.sitecore.net

Prequisites

  • Sitecore 9 or 9 update 1 (with a licence with JSS included)
  • Node JS version 6.9 or above
  • NPM version 5 or above

JSS Setup Steps

There are a number of steps required to Setup JSS before you can start developing using it. Follow all of these for the purposes of this post.

  1. Download and install the following two JSS server packages in Sitecore (using the package installer) from here: https://dev.sitecore.net/Downloads/Sitecore_JavaScript_Services/90_Tech_Preview/Sitecore_JavaScript_Services_90_Update_1_Tech_Preview.aspx
    1) Server Package (Tech Preview 9.0.1 rev. 180111)
    2) Infrastructure Package (Tech Preview 9.0.1 rev. 180111) – this is optional but is needed if you want to deploy your App to Sitecore via the command line

  2. Apply this to the web.config at the bottom of the system.webServer/handlers section:

    <add verb=* path=sitecorejss_media.ashx type=Sitecore.JavaScriptServices.Media.MediaRequestHandler, Sitecore.JavaScriptServices.Media name=Sitecore.JavaScriptServices.Media.MediaRequestHandler />

  3. Apply this to the web.config inside the system.webServer/modules section:

    <add name=”Sitecore.JavaScriptServices.Ship.ShipFilter” type=”Sitecore.JavaScriptServices.Ship.ShipFilter, Sitecore.JavaScriptServices.Ship” />

  4. Login to Sitecore Desktop on the Sitecore 9 instance you want to use. Switch to the Core database. In the Content Editor Navigate to: /sitecore/system/Settings/Services/API Keys
    and  insert a new API Key item, call it ‘JSS API Key’. Under AllowedControllers, which fill in the field with: “*”. Leave the rest of the fields as is. (more info on this step here). Take a note of the Item ID of the API Key item as you will need it in the next step.
  5. Verify everything works by going to:

    http://your-sitecore-instance/sitecore/api/layout/render/jss?item=/&sc_apikey={YOUR_API_KEY}.

    You should see something like the following in your browser:
    jss-test

Downloading & Testing a Demo App

Were going to use React for this and to keep things simple were going to use the simple React demo.

  1. Pull the JSS Demo source files from here: https://github.com/Sitecore/jss/tree/master/samples/basic-sample-react
  2. Go to IIS and add a ‘jssbasicapp’ as a new binding in IIS
  3. Edit your hosts file (C:\Windows\System32\drivers\etc\hosts) and add the following:

    127.0.0.1 JssBasicApp

    (you can change the name of the app and other settings if you want by editing: jss-basic-app.config)

  4. Open command line and go to the folder where you have downloaded the basic react sample (e.g: C:\Projects\Jss-Demos\samples\basic-sample-react).
    Run:

    npm install

  5. Next Run:

    npm run setup

  6. Next Run:

    npm run deploy-config

    You will be asked: ‘Would you like to configure connection settings to a Sitecore instance?’ – Enter Yes.
    When prompted enter your the Website Folder and Host of your Sitecore instance.

    (If you have any issues with this ensure you have your permissions set so allow the script to run and copy files over to your Sitecore instance)

  7. Lastly Run:

    npm run start

This will build the app and run a WebPack server, finally it should open up a browser showing the basic App at the following url: http://localhost:3001.

This will look like the homepage of a Standard Sitecore 9 install.

The App is not currently using Sitecore for data, it is being provided by local files within the app.

Deploying the App to Sitecore

Finally were ready to deploy the app to Sitecore and hook it up using real Data.

  1. Run:

    npm run deploy-codefirst

  2. Open up: http://jssbasicapp/ – you should see the following:
    jss-deploy1

  3. Lets double check it’s worked correctly by going to your Sitecore instance, opening Content Editor and going to: /sitecore/content/JSSBasicApp. You should see something Similar to:
    jss-tree

  4. Ok lets make a change to a component and re-deploy it to see the change working. Open up \samples\basic-sample-react\src\app\components\Welcome.js from the folder where you installed the demo.
    Edit the following lines to add a H2 tag with ‘Hello JSS’ in it:
    jss-component-update
  5. Open Command Line again and Run:

    npm run deploy-codefirst

  6. Again open up: http://jssbasicapp/ – you should see ‘Hello JSS’ show up:
    jss-deployed-2

  7. Finally go to: /Home in the Experience Editor, you should be able to edit the page as normal even though the Components are provided by JSS.

This is a really basic demo of JSS but it should hopefully show whats possible and get you started with working with JSS.

Props to Alex and his team for doing a great job and addressing the workflow of front-end developers with how they have approached JSS.

Auto-Setting Alt Text For Existing & New Images in Sitecore with Cognitive Services

Alt text on images is important for accessibility but often content editors do not set it or are not sure what to set it to.

I recently had the scenario where a client had thousands of existing images (across a Multisite Solution) with no Alt text entered and was asked to find a solution to add these retrospectively and also to make this easier going forward.

The Robots Are Coming

After considering my options (and reading a bunch of Blog Posts on how others have solved this) I decided to use Sitecore Powershell to set the missing Alt tags. This was because I only needed to run this once and then I won’t need to do this again.

However what should I set the Alt text too? It would be possible to use the image name in Sitecore or other attributes on the image in Sitecore to intelligently name the image. However often images have pretty non-descriptive names and no other data associated with them. An Alt tag of ‘IMG_20170416_085835‘ isn’t a great deal of use to users or screen readers. Therefore I wanted to use a more intelligent way of adding Alt Text.

robots

I’d seen this awesome presentations by Mark Stiles and Rob Habraken & Bas Lijten at Sugcon this year about using Machine Learning to solve problems just like this, and decided this was the way to go.

Mark Stiles has blogged about an full integration that he’s implemented with Microsoft Cognitive Services here: https://www.markstiles.net/blog/2017/2/22/sitecore-cognitive-services/

However I didn’t need all this functionality and this hasn’t been wrapped up into a proper Sitecore Module yet so I decided to go for a simpler approach.

Setting Alt Text for Existing Images

I stumbled across this really useful Post: http://www.pveller.com/image-tagging-automation-with-computer-vision/ by Pavel Veller which is what formed the basis of my script. It goes through each image in the media library and uses Microsoft’s Vision API to look at each image and return some appropriate Alt Text.

However given the number of images I needed to handle and complexity of the Multi-Site solution I’m working on I needed quite a lot more functionality. Therefore my script does the following:

  • Ability to run in test mode to output what it would do if run for real
  • Progress output as the script runs so you know how far through it is
  • Only updating Alt text when there is none set already
  • A CSV report at the end with the info for all images and the Alt text set
  • A list of TemplateIds to Exclude
  • A list of FolderIds to Exclude
  • Full error handling for exceptions
  • Pause for 60 Seconds and continue when hitting the Free API Limit (thanks Pavel Veller for this idea).
  • Tracking of failures/errors
  • Summary at the end of updated text and errors (if any)

Example Output

alt-text-screen-1

Example Summary

alt-text-screen-7

Note that to run this you will need an API key for the Vision API, so go and grab one from here:

https://azure.microsoft.com/en-gb/try/cognitive-services/

Show Me The Script Already

I’ve put the script here on Github and embedded it below: https://gist.github.com/fluxdigital/2b6041c579770f891df1a0da43cdcd63

The outcome of running this was that we auto-set alt text for over 1,500 images and could send the client a csv report of all of the alt text for each image for review afterwards (should they wish to check them, the API is not infallible, especially for Gifs/Pngs and other graphical images). This saved a lot of time for the content editors.

What about new images?

So this is great for the existing images, but how do we make sure that alt text is set in the same way for new images?. After a bit of investigation I decided on this great Module by Tom Dudfield which auto-sets alt tags on save of the image using the same Vision API:

https://marketplace.sitecore.net/en/Modules/A/Alt_Tag_Generator.aspx

This Module even works with the multi-file upload so it’s really good if users upload a lot of images at once and forget to go back and add Alt Text.

I did find and issue with the module where is doesn’t work if you use one of the free API Keys (as the base API url needs to be different), but I’ve fixed that and submitted a pull request to resolve this issue. The Module config will now support setting the base Url (to: https://westcentralus.api.cognitive.microsoft.com/vision/v1.0). Tom has merged my update in and will hopefully release a new version Via NuGet and the Marketplace soon, but in the mean time if you need the update you can find it here:

https://github.com/fluxdigital/AutoAltTags

Once you’ve installed this and configured it with your API key you should be good to go, no more empty Alt text :-).

Thanks to the Sitecore community for all the great posts on this that helped me with this, here are just some of them:

http://jockstothecore.com/optimizing-images-sitecore/

https://sitecorebasics.wordpress.com/2017/08/03/integrating-cognitive-services-to-set-alt-tag-during-image-upload/

https://tomdudfield.com/computer-vision-alt-tags-in-sitecore/

 

Auto-maintaining Sitecore Session State permissions in tempDB after SQL Server restarts

We use SQL Server to maintain our Sitecore sessions which mostly works fine. However as part of the performance boosts recommended by Sitecore the session-state is moved to store session in SQL Server tempDB.

The process is explained here: https://doc.sitecore.net/sitecore_experience_platform/setting_up_and_maintaining/session_state/session_state/walkthrough_configure_a_shared_session_state_database_using_the_sql_server_provider

However, every time that SQL Server is restarted, it recreates tempDB and resets the access rights for users and the session tables. This will result in your Sitecore site going down and an error such as:

System.Data.SqlClient.SqlException: The SELECT permission was denied on the object ‘SessionState’, database ‘tempdb’, schema ‘dbo’. The INSERT permission was denied on the object ‘SessionState’, database ‘tempdb’, schema ‘dbo’. The UPDATE permission was denied on the object ‘SessionState’, database ‘tempdb’, schema ‘dbo’.

And also an angry client and customers :-(.

How do I solve this?

You could re-run the script from the Performance boost download provided by Sitecore (Sessions db performance boost.sql ) but this could happen late at night when no one is monitoring your site and cause downtime.

The best way to solve this and still use tempDB for sessions is to offload this manual task into a stored procedure that runs on Start-up.

The following script will create a Stored Procedure in the Master database that will run each time SQL Server restarts and add your session tables and database user back to tempDB with the right permissions.

USE [master]
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = ‘P’
and name = ‘AddSitecoreSessionTempDBOwner’)
DROP PROC AddSitecoreSessionTempDBOwner
GO
CREATE PROC AddSitecoreSessionTempDBOwner
AS DECLARE @sql
VARCHAR(500)SELECT @sql = ‘EXEC [master].[dbo].[Sitecore_InitializeSessionState]’ + char(13) +’USE [tempdb]’ + char(13) +’IF NOT EXISTS(SELECT name FROM sys.database_principals WHERE name = ”Sitecore_Sessions”)’ + char(13) +’BEGIN’ + char(13) +’CREATE USER [Sitecore_Sessions] FOR LOGIN [Sitecore_Sessions]’ + char(13) +’ALTER ROLE [db_datareader] ADD MEMBER [Sitecore_Sessions]’ + char(13) +’ALTER ROLE [db_datawriter] ADD MEMBER [Sitecore_Sessions]’ + char(13) +’END’EXEC (@sql)
GO
EXEC sp_procoption ‘AddSitecoreSessionTempDBOwner’, ‘startup’, ‘true’
GO

Just remember to update ‘Sitecore_Sessions’ in the script above to the name of the user in your Sessions Database connection string, then run the script in SQL Server Manager to create the stored procedures that will run on start up.

How do I test this?

It is important to test this to ensure that on a restart of the SQL Server the script kicks in and works it’s magic. First check if the Stored Proceedure is set to run on Startup correctly by running this query:

SELECT name,create_date,modify_date
FROM sys.procedures
WHERE OBJECTPROPERTY(OBJECT_ID, ‘ExecIsStartup’) = 1

You should see the ‘AddSitecoreSessionTempDBOwner’ and ‘Sitecore_InitializeSessionState’ stored procedures listed. If you don’t try running the script above again as something went wrong.

Once these are listed correctly you should carry out a full test by scheduling in a time out of hours when you can reboot the SQL Server machine and check your script runs correctly.

Gotchas

One thing to ensure is running is the SQL Server Agent Service. This needs to be running in order for and startup stored procedures to be executed.

slq-agent

Check this is set to ‘Auto Run’ under startup type. This caught me out on my first test as my Stored Procedure didn’t run correctly on reboot of the SQL Server.

Lastly check your session state tables are collecting session data correctly using a query such as:

select count (*) from [tempdb].[dbo].[SessionState]

That should be it, no more problems with tempDB when SQL Server restarts.

 

Sitecore Stack Exchange Site Needs Your Help!

A while ago Mark Cassidy  started a Stack Exchange Site for Sitecore – our own Sitecore Specific Stack Overflow essentially .  Great idea right?

The Sitecore Stack Exchange Site Needs Your Help!
Calling All Sitecore Developers!

Myself and other Sitecore Community members have been trying to get the site (currently in Beta) to launch.

Due to Sitecore Symposium causing a downturn in activity for over a week we were initially told the site wasn’t going to make it out of Beta :-(.

However the good news yesterday was that Stack Exchange kindly relented and extended the Beta for another two weeks! until the 18/10:

http://meta.sitecore.stackexchange.com/questions/60/extending-the-private-beta-to-10-18

However if this is going to succeed we need more Sitecore developers / users to get involved. There are many of you out there but not enough on the Stack Exchange site.

If you have already signed up for Area51 then please use the site and start contributing.  Go to: https://area51.stackexchange.com/proposals/101710/sitecore and then use the “Visit” link under the “20 days in Beta” box, Or use this link: https://area51.stackexchange.com/proposals/101710/sitecore/visit and log in with the same details you used for Area51

If you haven’t already signed up, then ask for an invite in the #stackexchange channel on slack or tweet me @billyjava and someone will send you an invite.

I’m sure you will agree that our own Stack Exchange site for Sitecore would be a great asset to the Sitecore community and an really useful platform to share knowledge and documentation but if we don’t quickly get more support it won’t make it.

So please do what you can to help and support by asking and answering questions on the Beta site.

 

Sitecore Symposium 2016 – Day 1

Sitecore Symposium is an 2 day Conference for Sitecore Users, Developers, Partners, MVPs and just about anyone else who works with Sitecore.

This year it was in New Orleans and I was lucky enough to be able to come out for a few extra days to Explore NOLA and I can highly recommend it, a great city with some insanely good food, interesting history and friendly people.

img_9704

Day 1

On day One I was to learn a lot about the improvements and new features in Sitecore 8.2 including SXA, Sitecore Azure, Path Analyser and much more.

Opening Sessions

The opening session was kicked off in New Orleans style with an big Jazz band which certainly woke me up after the early start.

Interesting it was comedian Jake Johannsen who opened up and got us all in the mood before handing over to Micheal to kick off the first keynote.

img_9489

Micheal talked about empowering Physical and Digital experiences for customers and bought various users of Sitecore onstage to discuss how they are using Sitecore. Danone discussed the personalisation that they have done on their Baby early life platform for mothers and how they have used Sitecore to power this. It was really cool to see someone leveraging all the personalisation, profiling and automation features. Danone have seen an 800% uplift in sales from this. Their tips were: Build data first, start now and don’t wait for the tech to all be there to do it.

img_9492

One of the most interesting things shown was Sitecore Experience Accelerator (SXA) which allows you to create a new site in Sitecore, Wireframe it, Add Content, Export the wire frame and import a theme for it. It is Responsive out of the box and could be a really quick way to stand-up a Sitecore site quickly. I would learn more on this later.

Micheal announced that Sitecore has now built commerce in out of the box and it is fully integrated and supports personalisation. This is great news for those with Commerce aspects to their Sitecore sites.

Next up was Jason Silva who is a Technologist & Futurist. He was very engaging and had some interesting ideas about the future of Nueroscience and Nano Technology, ‘Hacking Life Itself’ and how Tech evolves exponentially. He made me re-think the barriers between tech and science and ‘Playing God’ stating that ‘There is no duality between nature and technology, they are 1 of the same’.

img_9505

Developer Keynote

Lars Nielsen took to the stage to share some information on Sitecores product strategy. He talked about xConnect and oData which are coming soon and will provide much better APIs for working with data in Sitecore. He then discussed Express Migration Tool which allows you to go from Sitecore 7.2 to Sitecore 8.2 in an automated manner.

img_9511

He touched on the NuGet feed that is now available for Sitecore, I think this is the thing most developers have been waiting a long time for (I saw a whole lot of Tweets about it when it was released a few weeks ago). The Official Sitecore Nuget can be found here: https://sitecore.myget.org/gallery/sc-packages.

img_9509

Lars introduced Antony Hook who talked about how Sitecore manages new feature requests using ProdPad and the ways in which these requests get to the Sitecore product team. Great to hear they are opening up user voice to non MVPs https://sitecore.uservoice.com/ and about the new Stack Exchange http://sitecore.stackexchange.com that is nearly out of Beta.

img_9524

img_9531

One things for sure Sitecore’s Community is huge and growing every day, just look at the stats above!

We also heard about Helix (the new name for the the design principles that underpin Habitat) http://helix.sitecore.net/. More on this later.

img_9518

We also saw a quick overview of Sitecore Path Analyser which looks great, I watched a demo of this by the Sitecore Product team in the Partner Pavilion and was impressed by the UI and functionality it provides.

img_9494

 

img_9560

Azure Sessions

It was the time to attend the first of the developer sessions and I chose two on Azure since this is something I’ve been looking at recently.

img_9535

The first was Sitecore in The Cloud: Architecting in AWS vs Azure where Peter Petley shared some info on his recommendations for deploying Sitecore to the Cloud. He talked about the performance of AWS vs Azure and I was surprised to learn that Azure performs better in general.

img_9539

He also talked about some of the new features for Azure that will be supported in Sitecore 8.2.1, more on this later.

img_9540

img_9543

One of the key takeaways here was the Paas doesn’t really work properly (there are reliability issues with some modules etc) so Iaas is still the way to go. Redis Cache was also recommended due to it’s great performance.

img_9548

 

img_9549

The above slides are a nice little summary of which platform wins out.

Next up was Ciaran McAuliffe’s session: Better Together: Sitecore on Azure. He dove into the Sitecore 8.2.1 Azure dashboard and showed us the power of App insights with things like Sitecore Logs, APV Map, Server Responses and Rules.

img_9553

Ciaran explained how Azure search is used instead of Lucene and that for cost and performance reasons you should only setup the indexes you need and use (not all Sitecore indexes in the configs).

Sitecore 8.2.1 comes with Data Packs out of the box that will pre-configure Azure for you, there is no need to use the Sitecore Azure Module anymore – it is being phased out. There will be Data Packs for CD and CA servers and everything will be setup for using the web deploy engine. The automation scripts are JSON based and ARM Templates will be provided xDB, XP etc to build out environments and the resources required as a base level for each.

img_9555

There are parameters files that go along with the ARM Templates that define the various variables, essentially 2 JSON files and an Powershell script is all that is needed to deploy Sitecore to Azure.

img_9554

We were shown the different plans that can be used for the various services required to run Sitecore on Azure he also discussed how Sitecore are also working on GeoLocation in Azure and using Slots to allow for environments to be replicated easily (e.g Staging and Production).

This all seems like a vast improvement to the current Sitecore Azure offering and should greatly simplify the process. It should be available from January 2017 so well worth waiting for if your looking to move to Azure soon by the looks of things.

SXA – Sitecore Experience Excellerator

After a spot of (excellent New Orleans style) Lunch I went to see Kerns talk on SXA – Sitecores new offering to get you a Sitecore site up and running very quickly. I’d heard a lot about this and it sounded very interesting so was keen to find out more. It is installed as a separate package in Sitecore . It is installed as a separate additional package in Sitecore with an associated costs a percentage of the Sitecore license.

img_9564

SXA allows you to create a new Site from within the Sitecore Content Editor Interface (nice). Sites need to be created within a tenant – a business unit with different visitors but which exists within the Same Sitecore instance. Tenants are created first (again within the CE).

Once you’ve created a site you will see it has created a folder structure that follows the Helix principles (from Habitat) so you will see familiar folders here such as foundation and feature.

img_9591

Kern then showed us how pages can be quickly put together using page designs and partial designs and 70+ pre-built components.Standard values are no relied on that much, instead XML is layered to create the pages and dynamic placeholders are available out of the box. The pages built will not have a design, they will look like wireframes, this is intentional.

img_9567

Kern then showed us how the wireframe layout can be easily exported using a button in the SXA toobar, then the zip generated can be provided to an front-end team or 3rd party to style before it is imported back in. Kern demonstrated this by quickly importing a pre-made theme and it automatically styled all of the pages and components. Impressive stuff.

img_9578

We were then shown a bit more detail on how these themes are created. Essentially it uses the 960 grid system so supports mobile out of the box, Bootstrap and Foundation are not currently supported. The themes are made up of individual CSS files, Images and JavaScript but optomised versions of these are served from the Site. Developers can add addtiional classes to the HTML when theming but can not change the structure of the HTML.

img_9579

Kern mentioned a few restrictions around using SXA, all data sources must use Items to us the standard components provided with SXA. However it is possible to build a standard component and use it within a SXA site. It does need to inherit from special SXA specific rendering classes to work.

img_9586

Deployment of a SXA site (assuming no customisations) is just a simple case of publishing the Site. All all this seems a great way to standup a Sitecore site quickly and with limited investment in development. It is perhaps though limited to Sites without the need for medium to high customisation. It will be interesting to see how SXA improves over time as it is something Sitecore are going to continue investing in.

It was now time for me to go and enjoy the beer in the Partner Pavilion and meet a few new people. I was already looking forward to Day 2.

My thoughts on SUGCON 2016 – Day 2

badgeThere was an early start for Day 2 (especially after a late-ish night involving a few strong Danish Beers), but I knew there were some intriguing talks today so didn’t want to miss anything.

You can read about Day 1 here if you missed it.

The first session that caught my interest was Nick Wesselmans talk on how Active Commerce use SIM, Powershell, Octopus Deploy and Azure to automate product builds.

Using SIM, Powershell, Octopus Deploy and Azure to automate product builds.

Nick gave an overview of how they created a PowerShell wrapper for SIM to automate Sitecore instances for product builds for their Active Commerce product.

IMG_5762

He also talked about how they use Sitecore Power Shell Extensions (SPE) to do things like automate publishing, rebuild the links database and initialise Sitecore Zip package builds. I’ve experimented with SPE but I’ve not used it in anger and this has given me ideas for how I might use it more on current or future projects.

IMG_5764

Finally, he talked about their use of Octopus for deployment of packages and invoking PowerShell scripts and Azure IaaS and Azure Blob Storage and AzCopy which is used for quickly spinning up VMs for hosting the product build and test environments. I liked the idea of these being scripted to only run during business hours.

IMG_5768

The Active Commerce team also use Bamboo for their build server (but are thinking of moving to Team City). Nick showed us that their build pipeline looks like this:

IMG_5773

It was nice to see some familiar approaches here, albeit with different tools in some instances and some new ideas too.

You Me and Sitecore MVC

After a short break Kern Herskind delivered and entertaining (and Circus themed) presentation on Sitecore MVC. He even rode a unicycle at the end!

IMG_5777

Kern gave a general overview on MVC for those not familiar with the concepts and then how Sitecore MVC works and whats available out of the box. Not much of this was new to me but it was good get a refresher anyway.

Then Kern talked through some of the downfalls of Sitecore MVC and how he has gone about solving them. Things like renderings not being able to alter any HTML that is rendered prior to them being rendered and multiple form posting issues.

IMG_5781

IMG_5782

IMG_5783

We then go a sneaky peak of what coming up for Sitecore MVC, such as abstract base classes and better ServiceLocator and DI support:

IMG_5869-3

IMG_5873

Kern finished by talking about the future of Sitecore MVC and expectations for the future.

IMG_5787

Good to see better documentation and closing feature gaps on the list of improvements.

IMG_5788

The key message here being that Sitecore MVC is going to continue to be the preferred UI Framework.

Hedgehog then did a quick talk on their TDS product and helped to answer the question a lot of developers might have, “why should I pay for TDS instead of using Unicorn”.  The answer is probably in these two slides, maybe go and show them to your Boss :-).

IMG_5791

Essentially it does a lot more besides just syncing items between sitecore instances:

IMG_5792

I haven’t used it but I’ve head good things about it from other Sitecore Developers.

After lunch (which was excellent by the way) I opted to attend two talks on Sitecore Habitat. One by Ruud Van Falier called Introducing Sitecore Habitat and the 2nd by Anders Laub on Practical Habitat: Embrace the Architecture.

Introducing Sitecore Habitat

For those who don’t know what Habit is, it is an Architecture approach for Sitecore development and is designed to give best practice guidance on how to structure your Sitecore projects. I have taken a look at it a few times but not really used it and the feedback from other Sitecore developers I’d spoken to was that it was quite complicated, so I was interested in finding out more about it.

Ruud was presenting to a packed room with quite a few developers stood up at the back, obviously as keen as me to know more. He started with the basic concepts of Habitat, explaining how all modules are self-contained and that there should be no communication that goes upwards between modules.

IMG_5796

He also explained the the 3 layers of Habitat: Foundation, Features, Projects.

layers

Ruud then discussed examples of elements that might live in these layers and how the dependencies flows downwards.

IMG_5806

He then showed the technology stack, which are probably familiar tools to most of you. Sitecore 8.2,  MVC,  Dynamic Placeholders, Unicorn, Bootstrap, JQuery, Sass and Gulp.

A run-through of the Habitat solution structure then followed and an explanation of the different build tasks used.

build

There was then a more in-depth explanation regarding Modules:

IMG_5816

IMG_5818

IMG_5820

And then more detail on layers:

IMG_5822

IMG_5828

IMG_5832

IMG_5834

Finally, a pros and cons slide and questions:
IMG_5836

Ruud was honest about the fact that Habitat is in the early stages and is changing every day, he also said it’s not meant to be taken as a ‘Boiler Plate’ for Sitecore solutions – more a guideline. However, I left the session will a lot of things to investigate further and will definitely be taking a closer look at Habitat and how some of It’s concepts can be applied to the projects I am working on.

Practical Habitat: Embrace the Architecture

With my appetite now whetted for Habitat I went straight to the next session on embracing the architecture.

Anders talk started with a general discussion around Architecture and then moved to Habitat and why Pentia use it as an architecture for their solution:

IMG_5837

He then dived into a demo of their solution and explained how it differs to the default Habitat setup. I have a video of this somewhere which I’ll try and add here when I get a minute.

He then discussed a few foundation modules they have created and how it really works well for them as an approach.

IMG_5840

Anders took some tough questions from the crowd well (such as the number of projects in Habitat – which is many) and I think by the end of the session most of the room will be taking another look at Habitat.

Ladies and gentlemen start your testing.

Testing in Sitecore can be notoriously difficult and for some Sitecore developers this means that unit and integration tests that involve the Sitecore context or items are sometimes skipped.  I was interested to see if Alastair had some other ways to implement testing and I wasn’t disappointed :-).

IMG_5844

Alastair Deneys ran us through 4 ways in which to Unit test with Sitecore. The first was an interesting one and was to essentially install Sitecore in your application and then run the tests from an asp.net web page test runner.

The 2nd and 3rd were to add a minimal or full Sitecore config files and the Sitecore dlls you need to your nunit test project and run It. This worked pretty well but as Alastair said, isn’t proper unit testing as it’s using real data.

The 4th was to use FakeDb to mock the Sitecore items you need to run your tests. I’d heard about FakeDb before but not used it so it was nice to see an example of how this is done.

IMG_5855

Alastair also showed us how Sitecore.LiveTesting can be used to spin up an instance of Sitecore in a container in the background to test against.

IMG_5856

IMG_5863

It was a bit slow but seemed really cool and definitely something I’m going to experiment with.

IMG_5868

The key message here was, whatever you do make sure you create tests and don’t get hung up on if they are real unit tests or actually integration tests.

Sadly it was now time to head to get our flight home so I missed out on the last talk of the day by Martina Welander on refactoring doc.sitecore.net, hopefully I can find it on Google Hangout.

SUGCON was a great experience and It has given me a whole lot of ideas and things to look into for current and future Sitecore projects. Thanks to the Sitecore Community and the sponsors for putting on the event.

My only regret is not having chance to chat to any of the MVPs who have been so helpful on Slack and on their blogs, but I’ll definitely be back next year so I’ll buy you a beer or two then instead.

Till next time.

IMG_5878

My thoughts on SUGCON 2016 – Day 1

SUGCON Venue

I was lucky enough to arrive at my very first SUGCON a day early and see at bit of the Copenhagen. It’s beautiful, everyone is very friendly and the food and beer is impeccable, if you get chance to go then you definitely should.

 

Opening Keynote

Day 1 of SUGCON kicked off on Monday afternoon with an opening Keynote from Lars Nielsen (Sitecore Co-Founder & Chief Development Officer). This was to prove one of the most intriguing presentations of the conference as Lars revealed a number of new features coming in Sitecore 8.2.

8.2

One bug-bear for a lot of Sitecore clients is the upgrade process, Lars assured us that in 8.2 (using the Express Migration Tool) this is going to be much easier and won’t involve upgrading in multiple steps (as is currently the case) and that is should be possible to move from 6.5 > 8.2 in one automated step. This is great news for those running 6.5 and 7 solutions as it should make the process a whole lot easier and quicker.

Lars then followed this with an overview of 8.3 features (sorry It’s blury):

8.3

The most interesting for me (and clients I work with) was the Webforms for Marketers is going to be removed in 8.3 and replaced by an out of the box module, which will look something like this:

forms

This looks a whole lot better than WFFM which as most Sitecore developers know can be a pain to customise and is pretty clunky to use.

This was reflected by the attendees as there was a round of applause from the room when this was announced. It will work in the experience editor allowing in-place editing – just like other Sitecore components, so content editors should find the experience simpler and more intuitive. There will be integrations with automation plans too:

forms2

In summary these are the Roadmap themes:

roadmap

This was a great start with lots of useful info about the future releases coming up!.

 

Serialise all the things with Unicorn

Next up was Kam Figy, an MVP at Connective DX and the lead developer of Unicorn – a tool for serializing your Sitecore Items to disk so you can check them in to source control alongside your code.

unicorn

Kam ran through a demo of Unicorn 3 which I’ve already used, but it was nice to see a full demo and find out more information about other options the we could potentially make use of.

He then showed us a project he’d done for the Sitecore hack-a-thon, which allows unicorn to sync Roles and Users as well as Items. This could be useful for future projects and is now available in Unicorn 3.2 (https://www.nuget.org/packages/Unicorn).

sync

Kam’s talk was entertaining and he managed to handle the slightly awkward Hedgehog vs Unicorn questions afterwards pretty well too :-).

 

After a short break the talks split off into different tracks for the rest of the afternoon and I went with these 3:
Atomic Design Talk by Tim Braga, Design Patterns by Mike Reynolds and then Building Large Scale Sitecore solutions by Mike Edwards.

Atom Design to the MAX

Tim talked through the different approaches to building Sitecore Sites and then explained why instead of just going down to component level (as most Sitecore developers do) his team now breaking every element of a component down further into Atoms and making these separate renderings.

atomic

This allows for more control over functionality, layout and personalisation/testing on a more granular level – e.g. A/B testing on just a single button. Below is an example of this for the Hero that Collette created:

hero

There were however some performance issues found though with Experience Editor and it does add time for development, testing and content entry. Tim went over the pros and cons and what they have carried out to try and work-around some of them:

proscons

I like some of the concepts but I’m not yet convinced this is the way to go for most Sitecore builds, unless there really is call for this level of control.

 

Design Patterns

I wasn’t sure what to expect with this talk but I was a bit surprised to see it was less Sitecore focused and more around Design patterns and their usage in programming in general.

design patterns

Still it was good to see examples of their usage with Sitecore from Mike and the pros and cons of each approach.

pattern

 

Building Large Sitecore Solutions

This talk by Mike Edwards was really good. Mike gave and overview of the infrastructure and architecture of Sitecore solutions as they grow and require more CD servers and xDB provisioning.

scale

He talked about blue/green deployments and the importance of trying to have zero downtime for client sites during deployments. He also discussed load balancing strategies and the pros and cons of the different approaches.

blue-green

I’ve had first-hand experience of doing this for a few clients and it’s good to see some of the ideas we’ve used re-enforced by Mike, such as having two web databases in place so that one can be used for deployment whilst the other is live.

The architecture with xDB included looks pretty crazy but this demonstrates the number of servers and considerations involved with xDB:

xDB

After this (and a short talk by Coveo regarding their Search product) it was time to drink beer, eat food 🙂 and chat to some other Sitecore people.

There were also awards given out for the Sitecore MVPs (well done guys) and a Sitecore quiz with beer to be won.

All in all a great first day and some really informative sessions. I was really looking forward to Day 2.