Sitecore
Invert list selection with Sitecore PowerShell

Invert list selection with Sitecore PowerShell

I recently needed to run a script on a block of Sitecore content in invert the selection of a checklist and multilist. As I couldn't find any example of how to do this at the time, I thought I'd share what I wrote.

1#script to update tier
2Get-ChildItem -r -Path "master:\content\Home" -Language * | ForEach-Object {
3 if ($_.PSobject.Properties.name -match "Tier") {
4 [String[]]$tiers = $_.Tier -split "\|"
5
6 $_.Editing.BeginEdit()
7 $newtiers = Get-ChildItem 'master:\content\Lookups\Tiers\' | Where-Object { $tiers -notcontains $_.Id }
8 $_.Tier = $newtiers.Id -join "|"
9 $_.Editing.EndEdit()
10 }
11}

Get-ChildItem -r -Path "master:\content\Home" -Language * | ForEach-Object {

This line is getting the child items from the home node in the master db. The -r specified that it should be recursive and the -Language * specifies to include all languages. The results are then piped to a for each loop.

if ($_.PSobject.Properties.name -match "Tier") {

The field I needed to update was called Tier, as this was included in multiple templates I checked that the object included a field called Tier, rather than checking the template types.

[String[]]$tiers = $_.Tier -split "\|"

List fields in Sitecore get stored as a pipe separated list of the item Id's for the selected items. In order to do a comparison in Powershell I needed to turn the string back into an array using the split command. Notice the backslash that is needed before the pipe.

$_.Editing.BeginEdit()

To edit an item you need to begin an edit

$newtiers = Get-ChildItem 'master:\content\Components\Lookups\Tiers\' | Where-Object { $tiers -notcontains $_.Id }

This is where we get the new list of tiers to set as the selected ones for the item. The Get-ChildItem command is retrieving the original options that could be selected and the where-object statement is then excluding the ones that are in the $tiers array we just made.

$_.Tier = $newtiers.Id -join "|"

To save the new list we need to convert the results of the query into a pipe separated list using a join.

$_.Editing.EndEdit() } }

End the editing to save and close the the if and loop statements.

Top features in Sitecore 9

Top features in Sitecore 9

Sitecore 9 is out and with it comes cool new whizzy stuff. Here's my top features from the new version of the platform.

#1 - New Forms module

I think everyone would agree that Web Forms for Marketers was starting to show it's age and the UI was getting a bit dated compared to the rest of Sitecore.

The new Forms module, which is just called forms is completely new from the ground up. It has a new drag and drop UI with long awaited support for multiple page forms.

Like WFFM, the module is extendable through custom save actions and comes with a number of useful default ones out of the box.

There is no upgrade option for moving a WFFM form to the new module but WFFM will continue to work on Sitecore 9 and is being dropped in Sitecore 9.1.

I think more than anything the UX improvements will make a real difference for users by being much simpler to understand and will drive to much more use.

#2 - Marketing Automation

In Sitecore 9 Engagement Plans are being replaced with Marketing Automation. Like the forms module, this is completely new from the group up rather than an UI update to the existing Engagement Plans.

The new Marketing Automation module has a really easy to use drag and drop ui which is a vast improvement over the old Silverlight implementation engagement plans had. It's also directly accessible from the dashboard rather than being hidden in the Marketing Control Centre.

One of the biggest changes (aside from the UI) is there is now no need to enrol users in a plan at a specific state either by code or a wffm save action. I found this one of the most confusing aspects to end users who were expecting creating states with a trigger to automatically add people once they had triggered a goal, so this is great to see fixed.

Plans now have very clear start and end points with a number of options on the start node (goals, events), which can be combined to trigger who should be added to the plan.

Overall for the moment you try creating a plan just to see what it can do, the whole process is so much simpler that I think this will have a significant aspect on users. Engagement Plans were something that needed to be learn 't in order to get anything out of them, and wernt intuitive enough leading to frustration. With Marketing Automation I think a lot of people that were put off before will now benefit from this module.

#3 - xConnect

xConnect is a new service layer that sits between xDB and the client. That could be the CMS, a device or some other custom server side process that needs to read or write xDB data.

With xConnect as the service layer this means that no system has direct access to the collection database or search indexes. Any system wanting to access this data will go through xConnect which also helps with support for things like GDPR.

xConnect is installed separately from Sitecore itself and does not have any dependencies on the Sitecore kernel. When you install Sitecore locally you will see two IIS entries, one for Sitecore and one for xConnect. Communication with xConnect is done via a set of RESTful API's over HTTPS, making integrating with it extremely simple to do.

What xConnect really brings to the table is the ability to scale an combine many more systems rather than just the CMS. e.g. Phone Apps.

#4 - Sitecore Installation Framework (SIF)

Installing Sitecore 9 is very different to previous versions (see my Sitecore 9 installation tips here), gone are the days of copying a web-root and restoring some db's. The entire installation is now done with a new framework based on PowerShell scripts.

While this is going to create a pain point in the amount of time it takes to get started. It will almost certainly vastly improve DevOps tasks as it opens up numerous options to put the installation scripts in deployment pipelines.

Sitecore 9 installation tips

Sitecore 9 installation tips

Sitecore 9 released this week and with it comes a whole new installation process. Gone are the days you could just download the web root and restore some dbs or just run the installation gui and enter a db connection string. Sitecore 9 has some fairly fundamental architectural changes with multiple IIS entries and and some windows services to go with it. Server roles are now also being properly configured rather than updating config files to match what it says in an excel doc.

Along with these changes, the installation process has moved to be based on powershell scripts, which on one hand has made things a bit harder, but it also brings great positives that the process can now be customized with scripts that are repeatable without the risk of mistakes.

Here's my tips for a smooth local installation (production installs are different to a local install).

Tip #1 - Check the Prerequisites and Requirements

It sounds obvious but when presented with a new toy you want to play with it as fast as possible, and with a 49 page document the urge is there to skip to the installation and hope for the best.

Skipping however is likely to result in install failures as the installer relies on modules such as Web Deploy and the right version of SQL Server which were not needed for the version you may already have installed.

Tip #2 - Make sure you have the right versions

You may have SQL and Solr but are they the right version?

SQL Express 2016

Sitecore 9 supports SQL Server 2014 SP2 and SQL Server 2016. Now that SQL Server 2017 is out, actually finding the link for 2016 express has become a challenge, but here it is.

Download SQL Server 2016 Express

Solr 6.6.1

Sirecore 9 supports Solr version 6.6.1. I typically use Bitnami Solr as it's a lot easier to install than doing Solr on it's own. Like SQL though the latest version is newer than what Sitecore supports and finding the link to the older one can be a bit of a challenge.

Download Bitnami Solr 6.6.1

Tip #3 - Solr requires SSL

By default Solr does not install with SSL turned on, but without it your install will fail. More specifically it will fail trying to start an xConnect service.

Enabling SSL for Solr

To create a self-signed certificate for Solr we can use the JDK Keytool which if you've installed Solr you should already have installed.

Note: These instructions are based on this guide from Apache and this blog post from Jason St-Cyr.

  1. Open command prompt
  2. Change to the Solr ‘etc’ directory
1cd "{SOLR_HOME}\server\etc"

3. Execute the keygentool command

1"{JAVA_HOME}\bin\keytool.exe" -genkeypair -alias solr-ssl -keyalg RSA -keysize 2048 -keypass secret -storepass secret -validity 9999 -keystore solr-ssl.keystore.jks -ext SAN=DNS:localhost,IP:127.0.0.1 -dname "CN=localhost, OU=Organizational Unit, O=Organization, L=Location, ST=State, C=Country"

This will generate the keystore with a password of ‘secret’ as valid for localhost and 127.0.0.1. You can add other DNS and IPs as desired, or skip hostname verification.

4. Convert generated JKS to PKCS12

1 "{JAVA_HOME}\bin\keytool.exe" -importkeystore -srckeystore solr-ssl.keystore.jks -destkeystore solr-ssl.keystore.p12 -srcstoretype jks -deststoretype pkcs12

5. Enter password when prompted. The password ‘secret’ was used in the previous step. Remember to use your password instead if you changed it in the keygen command parameters.

6. Open Windows Explorer and navigate to the ‘etc’ directory (“{SOLR_HOME}\server\etc”)

7. Double-click on the generated ‘p12’ file (solr-ssl.keystore.p12 if you used the default parameters from the previous steps)

8. In the wizard, specify the following values (there will be some extras you can ignore):

Store Location: Local Machine

File name: Leave as provided

Password: secret

Certificate Store: Trusted Root Certification Authorities

Remember to use your password instead if you changed it during the previous steps.

9. Open the solr.in.cmd file for editing (e.g. {SOLR_HOME}\bin\solr.in.cmd)

10. Un-comment the SSL settings:

1set SOLR_SSL_KEY_STORE=etc/solr-ssl.keystore.jks
2set SOLR_SSL_KEY_STORE_PASSWORD=secret
3set SOLR_SSL_TRUST_STORE=etc/solr-ssl.keystore.jks
4set SOLR_SSL_TRUST_STORE_PASSWORD=secret
5set SOLR_SSL_NEED_CLIENT_AUTH=false
6set SOLR_SSL_WANT_CLIENT_AUTH=false

11. Restart SOLR to pick up the changes.

Tip #4 - Close management studio

I'm not sure if this was a one off thing, but with management studio open my installation failed with a single user access issue.

Tip #5 - Check the logs

The installation script will output logs to the folder it runs in. If your installation fails it will reference a log file. To find out why the installation failed or get some more info go and check the log referenced.

Tracking downloads in Sitecore Experience Analytics

Tracking downloads in Sitecore Experience Analytics

This blog is generally aimed at developers whereas the contents of this post could be categorized as a topic for marketers, but I've decided to include it as its likely something a Sitecore dev could get asked about and its also quite useful to know about.

Out the box Sitecore's Experience Analytics comes with a set of pre-configured reports to give insights into the sites visitors. Previously I blogged about Populating the internal search report in Sitecore which unless done will probably lead to someone asking why it's blank. Another report which initially won't show any data is downloads.

Located under behavior there is actually now two reports relating to downloads. The Assets report and the Downloads report.

Assets, in Sitecores words - "Describes your marketing assets or content used to attract contacts to your website and increase their engagement with your organization."

Downloads - "Describes your specific assets, their download activity, and their value."

These reports are populated by assigning a download event to a piece of media and organizing it as a marketing asset.

Adding a download event to an item

Sitecore doesn't know which items you think are important to track as downloads so content editors need to mark them manually.

Go to the Media Library

Select the item you want to track as a download

From the ribbon select the Analyze tab and click Attributes

Select download form the list of events

Remember to publish your changes.

Categorizing an Asset

By assigning a marketing asset type to your items they can be grouped for analysis. Such as grouping downloads into categories like white paper and product brochure.

Before you assign a marketing asset to an item you will first need to create your assets. On the Sitecore Launchpad, open the Marketing Control Panel.

Go to Assets which is located under Taxonomies.

Create your set of Asset Groups and Assets within each. In this example I've created a group called Content and Assets called Instruction Manual and Product Brochure.

Navigate to the item you want to assign the asset to and select the relevant asset in the marketing asset field.

Publish all your changes.

The result

Now you've set a download event and a marketing asset, the assets and downloads reports will start populating.

Going Further

The concept of having to tag every download as a download may seem a little tedious and also prone to being missed in the future. If all your downloads are PDF's and you want to track all PDF's as a download, one way to make life easier is to update the standard values on the PDF template item (/sitecore/templates/System/Media/Unversioned/Pdf) so that it always has the attribute of download. The content authors will still need to do the marketing asset categorization, but at least this gives them 1 less thing to do.