Wednesday, September 23, 2015

Sitecore get media item from ID

When dealing with fields which are of the ImageField type is is trivial to get the media item (image) that is referenced in that field. However when using a Treelist field, which allows users to select images, you are given a delimited string of item IDs of the selected image(s).
var item = Sitecore.Context.Database.GetItem(mediaItemID);
if (item.Paths.IsMediaItem)
  var mediaItem = new MediaItem(item);
To get the MediaItem, simply get it as a normal item (to ensure it exists and is actually a media item) and then parse it as media item.

Monday, September 21, 2015

Sitecore Web Forms for Marketers Overview and how-to guide

Most web sites on the internet will have some sort of form available for users; from a simple form that accepts an email address to subscribe to a newsletter all the way through to a large data entry form with complex business rules and logic. Setting up the web form and making any modifications will often require developers time and code deployments, something which is not ideal in the fast-paced and often responsive world of marketing. Sitecore has an innovative approach to online forms with it's free Web Forms for Marketers module.

The module empowers content editors to create their own web forms, choose a form action (such as emailing the data to an address), then display the form on the desired page(s), ready for users to complete. The form creation process follows a simple user interface that requires minimal training, adding the form to a page is the same process that content authors will be familiar with, and the number of form save actions should meet most business requirements with no custom development time.

The form creation interface

Once you create a form in the content tree, you have the option to open the form designer. This is the area where the form elements are created and general settings such as: title, introduction and footer are set. There is also the option to export the form to ascx (which developers can use to bring the form into custom code without having to redo the form manually). 

Web Forms for Marketers ribbon

There are many different field types which can be added to the form, such as simple text, or more complex types like email or phone number which have pre-defined validation. The list types such as Drop List or List Box allow a data source off of the content tree, which allows for selections from existing content (this could be custom categories for example, or even business departments).

Web Forms for Marketers field types

Validation can also be manually applied to any field on the web form, the default validation types include: numbers only. letters only, special characters must be included, number and special character and email address. With custom validation you have the option to use a regular expression (which allows you to validate on a custom pattern), an example of this would be a member number or ID which would have format and length governed by business logic.

Web Forms for Marketers form designer example
In the form designer example above, I have created a simple contact form. It accepts a first/last name, email address and user comments. Key fields are set to be required and the email address is set to the email form (which includes validation by default).

The form Save Actions

Once the interface of the form is designed, the save actions need to be set so that the data entered into the form actually goes somewhere. The following save actions are currently available out of the box in Web Forms for Marketers:
  • Add the contact to a contact list
  • Change Password
  • Enroll in Engagement Plan
  • Update Contact Details
  • Create Item
  • Create User
  • Edit Role Membership
  • Logout
  • User Login
  • User Login with Password
  • Send Email Campaign Message
  • Send Email Message
  • Send MMS
  • Send SMS
  • Tell a Friend
  • Register a Conversion
  • Register a Campaign
It is also possible to select any number of these save actions into the same form. One example of this may be registering a user and then enrolling them into an engagement plan. 

Web Forms for Marketers save actions

Each save action can also have a custom error message displayed on fail, this is good because it allows for granular error messages for key and non-key save actions. 

Web Forms for Marketers save actions error messages

For the contact form example above (in the form designer section), I am simply going to set the save action to Send Email Message. Once the save action has been added, the edit button needs to be clicked to configure that action. 

Web Forms for Marketers save actions configuration

The configuration for each save action is different, in the send email example we simply set the email options and the message itself. The field values are entered into the message using the insert field option and appear [Like So].

There is also a global configuration that needs to be setup for some of the save actions. Sending an email message for example requires email server details (SMTP) to actually send the mail. In this case, the configuration is set at: /sitecore/system/Modules/Web Forms for Marketers/Settings/Actions/Save Actions/Send Email Message. The important field to set here is Parameters - which should contain valid mail server details.

Adding the form to a page

Once a form is created, it can be added to a page (and even multiple pages) by using the Form (or MVC Form) rendering. These renderings are added to Sitecore when Web Forms for Marketers is installed and are available at: /sitecore/layout/Renderings/Modules/Web Forms for Marketers.

As content editors will be familiar with, the rendering can be added to any of the allowed placeholders via the content editor or page editor.

In the control properties window of the Form rendering, simply select the form created earlier. Once a publish is complete, the form should appear on the nominated page.


Web Forms for Marketers is a powerful module, that enables end-users to have complete control over forms used on a Sitecore site. It takes away the need for developer time and deployment, and allows content editors and marketers to respond to their needs right away, in a secure manner. 

As the how-to guide above shows, it's a simple process that will make sense and be easy to follow for users already familiar with Sitecore's content editing interface. It already comes ready with many save actions on the forms (for both simple and more advanced tasks), however like anything Sitecore, it's always possible to extend Web Forms for Marketers to meet any complex business needs.

Tuesday, September 15, 2015

The benefits of Sitecore's Email Experience Manager

In the past content management systems have lacked the ability to handle enterprise level email campaigns natively, and this has led to many marketing departments to utilise third party tools such as MailChimp or Campaign Monitor. For those organisations currently using Sitecore or considering using Sitecore, the email experience manager is the answer and I will detail the benefits of it over the competition.
  1. Cost: email experience manager is a free module offered by Sitecore. There are no monthly yearly fees applicable for using the module. There is a paid option/addon to send the email via Sitecore's servers, however you are able to use your own or a third party service. Sitecore offers the message transfer agent (MTA) service as a value add due to the risks with blacklisting of internal email servers due to perceived spam.

  2. Availability/Management: email experience manager is installed on your infrastructure (whether that be in the cloud or on physical servers) and completely under your control and not at the mercy of a third party located overseas (with limited support). This means all updates, downtime and security is managed by you, and any support is available via the helpful Sitecore support team and any Sitecore partners you may on the journey with.

  3.  Shared Content Items and Media: With third party email campaign systems, content is generally prepared in word documents and approved manually by emailing the document around. This is a risk because the content may change (both visually and textually) when entered into the third party system. With Sitecore, when preparing an email you have access to any content items and media library items available from your main web site. The real risk minimisation here, is that it's the same content items that passed the required workflows and were entered, approved and managed by the relevant stakeholders. This allows for easy collaboration between departments and saves a lot of time and headaches.

  4. Code Customisation/Extension: Third party systems are able to provide a service which meets the broad markets requirements, with no room for customisation or extension. When a unique business requirement, unique campaign or interactive campaign comes up, these systems are often not able to meet the brief. As with Sitecore as a whole a series of pipelines are exposed which give developers access to customise/extend how different parts of the CMS work. These pipelines really open up the email experience manager to unique customisation, for example the following is just a sample of what could be achieved with just one of the many extension pipelines:
    • Use the CheckPreconditions pipeline to require approval from a department/business manager before sending to a given recipient or recipient list.

  5. Use of Sitecore interface: The Sitecore interface for building a page and content up is simple, elegant and not time consuming at all. The interface is nothing but familiar across releases, and is not likely to change overnight like some third party tools. Email Experience Manager using the exact same interface as Sitecore CMS, means less training is required for end users, and if any help is required from the developers, they actually know the system well themselves. Remember this interface also gives direct access to the same web content and media as available on the web site.

  6. Personalisation: Personalisation is becoming bigger and better each year and many organisations are starting to realise the true power it offers in terms of providing the right information at the right time to the right user. Harness all of the information you already know about your Sitecore web site visitors and personalise emails just for them. Send email directly based on a user's browsing history, interests, past purchases and so on. Then take it a step forward and begin to anticipate their needs and email based on that. 

  7. Trigger Emails: With email experience manager, emails are not just sent manually whenever a newsletter is created and recipients added. You also have the ability to trigger emails and target your web site's users by the use of custom engagement plans. If a user registers to your web site, send them a welcome email. If a user starts going through a checkout process, but drops out before paying - send them a discount coupon to complete the sale. The opportunities with triggered email messages are endless and they lead to more goal conversions and a higher visitor engagement value. These emails are also not hard coded and maintained by developers, they are emails available for edit by content authors - as is the content/images they use.

  8. Send Emails from Custom Code: Many web sites have custom code with complex business logic that may require emails being sent. It is possible to send a message using code (to single and multiple recipients), as the logic requires. The benefit here, is that like triggered email (single recipient) the email messages are not locked away in the code but made available to content authors.

  9. The Sitecore Connected Experience: Sitecore offers a completely connected experience across all channels which no other system is available to offer. Email Experience Manager integrates right into the other Sitecore® Experience Platform™ offerings, which include; web site, commerce, mobile, social and even print. This allows for the complete customer journey h a unified front with consistent message and branding that ultimately leads to more informed and interested users.
Source: Sitecore

Sitecore parameters on the TreeList template field

The TreeList field in Sitecore is a great way of exposing items in the Sitecore content tree for selection. Not only does it take in a source field (which points to a parent item in the Sitecore content tree), but the source also accepts parameters which control the TreeList itself.

These parameters are built up as querystrings are: param1=X&param2=Y

  • DataSource: A path to where the data source is located
    • datasouce=/Path/To/Items
  • AllowMultipleSelection: Allow the same item to be selected on the TreeList (more than once), this is false (no) by default.
    • allowmultipleselection=yes
  • ExcludeTemplatesForSelection: A comma separated list of template names which are visible in the tree and not able to be selected.
    • excludetemplatesforselection=Template Name,Other Template Name
  • IncludeTemplatesForSelection: A comma separated list of template names which are visible in the tree and able to be selected.
    • includetemplatesforselection=Template Name,Other Template Name
  • ExcludeItemsForDisplay: A comma separated list of item names or IDs which are excluded from display in the content tree.
    • excludeitemsfordisplay=Item Name,Other Item Name
  • IncludeItemsForDisplay: A comma separated list of item names or IDs which are included in the tree.
    • includeitemsfordisplay=Item Name,Other Item Name
  • ExcludeTemplatesForDisplay: A comma separated list of template names which are excluded from the tree.
    • excludetemplatesfordisplay=Template Name,Other Template Name
  • IncludeTemplatesForDisplay: A comma separated list of template names which are included in the tree.
    • includetemplatesfordisplay=Template Name,Other Template Name
  • DatabaseName: Sets the name of the database being referenced.
    • databasename=OtherDataBase

Wednesday, September 9, 2015

Sitecore trigger a goal on a media library item

Goals are not just assigned to pages or programatic events, you can also trigger them on viewing of a media library item. For example if you had a brochure PDF file in the media item, it would be possible to set a "Download Brochure" goal on that item.

To achieve this, log into Sitecore, open the media library and select the item you wish to assign the goal to. From the top menu select Analyze and then Goals

Now select any goal(s) which apply to the media item.