Want to help your business user? Create a custom Macro

When talking to business users (people that actually work with Sitecore on a day to day base) I created a small list of minor custom changes that would help the business users with there day to day work.

One of the items on this list is the condition for User Profile fields, by default the input of this field is a manual typed String. Which is a painful process for the business user They are not sure of the fieldname and go to the usermanager to verify the name. And even when they know the fieldname they surely can make a typo. After all even a business user is just human.

Typo and human errors

So after a small thought I started coding. My solution for this problem is simple. Create  a custom Macro with a tree selection and return the item name! Let’s do this!

Create the custom Macro class

Open VS, and create a class called UserProfileFieldMacro that inherits from the IRuleMacro class.

Override the Execute method, in this method we need to define the custom Macro. Please read the code comments for explanation.

The UserProfileFieldMacro class has the following code
[code language=”c#”]
public class UserProfileFieldMacro : IRuleMacro
{
public UserProfileFieldMacro() { }

public void Execute(XElement element, string name, UrlString parameters, string value)
{
Database coreDatabase = Sitecore.Configuration.Factory.GetDatabase(“core”);

//Define default path to profile template
string profilePath = “/sitecore/templates/System/Security/User”;

//Check if custom path is set in Macro parameters
if (parameters.HasPath)
profilePath = parameters.Path;

Item userProfileRootItem = coreDatabase.GetItem(profilePath);

//The path isn’t correct, we want to log this error and send the user to the system administrator
if (userProfileRootItem == null)
{
string error = string.Format(“The path ({0}) set in the user profile field condition doesn’t exist”, profilePath);
Sitecore.Diagnostics.Log.Error(error, this);
SheerResponse.ShowError(error + ” Please contact your system administrator”, string.Empty);
return;
}

SelectItemOptions options = new SelectItemOptions();

//Set and hide the root of the tree in the dialog window
options.Root = userProfileRootItem;
options.ShowRoot = false;

//User can only select Templatefields
options.IncludeTemplatesForSelection = new List { TemplateManager.GetTemplate(TemplateIDs.TemplateField, coreDatabase) };

//Return the item name to the public property
options.ResultType = SelectItemOptions.DialogResultType.Name;

//Set dialog window info
options.Title = “Select User profile field”;
options.Text = “Select the user profile field to use in this rule.”;
options.Icon = “applications/32×32/media_stop.png”;

//Trigger the dialog window
SheerResponse.ShowModalDialog(options.ToUrlString().ToString(), true);
}
}
[/code]
Compile your code.

Create the Items in Sitecore

Login to Sitecore and open the content editor.

Create the macro item

Go to  the /sitecore/system/Settings/Rules/Common/Macros folder and create a new Macro item called UserProfileFieldMacro. Set the Type field to match your custom Macro class and assembly.

image

Create the condition item

Go to the /sitecore/system/Settings/Rules/Common/Conditions/Security folder and duplicate the User Profile Condition Item, name the duplicated itemUser Profile Field Selection Condition.

Now we need to change the Text field so it will use the custom create Macro instead of the default string input. Go to the Text field, I highlighted the part that we are changing

where user profile [FieldName,,,specific] field [operatorid,StringOperator,,compares to] [Value,,,value]

What you see is a four column seperated string. The four columns are representing the following functionatily:

  1. the public property in the condition that will be set.
  2. the macro used to get the user input (blank is string input)
  3. optional parameters to pass to the macro
  4. the text value that appears to the business user when the value is not set

Now change this to use the custom created Macro

where user profile [FieldName,ProfileFieldOperator,,specific] field  [operatorid,StringOperator,,compares to] [Value,,,value]

If you look at the Macro code you will see that if no parameters are passed we use the path to the default user profile. If you have custom user profile you can pass the path as a parameter. For example;

where user profile [FieldName,ProfileFieldOperator,/sitecore/templates/System/Security/Jetstream User,select] field [operatorid,StringOperator,,compares to] [Value,,,value]

Now where all set to test the new condition!

Activate and test the condition

Open the page editor and select a presentation component you want to personalize. Click the personalize button and create a new rule.

Select the for the where user profile select field compares to value  condition and click the red select link. The custom Macro will now fire the dialog window where all the profile fields are available for selection.

image

And the best thing is if the business user selects a Field section the a message will appear. No more humon errors here 🙂

So for my example I configured the following rule for a component called Summer sun.

image

Test the conditional rendering rule

If I visit the website as a logged-in user with the firsts name Pieter the Summer sun component will appear. Otherwise the component will be hidden.

Let’s visit the website as a anonymous visitor.

image

Now after I login with my account (and yes my first name is Pieter) the control will appear.

image

Wrap up!

This solution is specifically created for user profile fields, you could also create a more generic Macro with more custom parameters. For me the most important part is that I showed you how easy it is to create a custom Macro. The next time the business user confront you with their problems, don’t just tell them this is the way Sitecore works. Tell them that you can easily change the behavior of Sitecore within a few hours. And of course share your customizations with us!

Don’t forget to hide the old user profile field condition. Read the article about removing conditions and actions for you business user based on Security.

If you have any questions, comments or own customizations you want to share? Please leave a comment.

Happy coding!

Tested: Sitecore Wildcards and DMS statistics

With this test we want to check what Sitecore DMS does with Wildcards. How are Wildcard URL’s and shown on the Analytics Reports?

Wildcard items in Sitecore are a convenient way to handle dynamic URLs. They let you pass data through the URL instead of relying on query string values that are appended to the URL. More information about the Wildcards and a introduction to the Wildcard Shared Source Module can be found in this article (written by Adam Conn).

Creating a testing environment

For this testing environment I’ve installed the shared source Wildcard module. After installing the module I opened the Content Editor and created a ‘products’ item, underneath the products item I created a wildcard item (*).

image

Configure the Wildcard Module

Go to /sitecore/system/Modules/Wildcards/. Create a new token called ‘Product Detail’ in the Tokens folder. And create the a new route called ‘Product Route’ within the Routes folder. In the Product Route item add the Wildcard item (*) to the Items field and define the rule in the Rules field.

image

The Wildcard module comes with two Sublayouts; DisplayDynamicUrls and DisplayTokenValues. For this test we are going to use the DisplayDynamicUrls sublayout. We need to alter the GetSampleData() method in DisplayDynamicUrls.ascx.cs. Open the DisplayDynamicUrls.ascx.cs and navigate to the GetSampleData() method and change the code so it will look like the following code:

[code language=”csharp”]

//The following constants must match tokens defined in Sitecore
const string TOKEN_PRODUCT_DETAIL = “%Product Detail%”;

private List GetSampleData()
{
var list = new List();
list.Add(new NameValueCollection { { TOKEN_PRODUCT_DETAIL, “product1” } });
list.Add(new NameValueCollection { { TOKEN_PRODUCT_DETAIL, “product2” } });
list.Add(new NameValueCollection { { TOKEN_PRODUCT_DETAIL, “product3” } });
return list;
}

[/code]

Now add the DisplayDynamicUrls sublayout to the Layout Details of the products item.

The test

Generate analytics data

Open a new browser, clear all cookies (I use Chrome Incognito Window) and visit the products item. You can see that the DisplayDynamicUrls sublayout generates Sample links based on the Sample data you configured in the GetSampleData() method.

image

Click the Sample links and close the browser.

View the Latest Visit Report

Open the Latest Visits report in the Engagement Analytics and select the latest visit. In the bottom of report you can find the visited pages. You can see that Sitecore has logged the wildcard page visits.

image

The verdict

At this point there is no indication that Wildcards are causing any problems with Sitecore DMS statistics. This is a straight forward simple test without any other complex systems involved, implementing wildcard in combination with DMS on complex systems needs thorough testing before deployment. Consider creating a Proof of Concept before starting to developt your sollution.

Please leave a comment if you have experience with Wildcards and DMS in a more complex scenario.

Daily Tip: Use the Customized Startbar module

Tired of switching between the Master and Core database during development? Making the mistake of making changes on the wrong database? Install the Customized Startbar Module.

This module will do multiple things, but the main two things that I really like are:

  • You can add buttons to the Quicklaunch bar.
  • Add the database name next to the database icon (bottom right)

The startbar before installation

The startbar after installation

image image

You can download the Customized Startbar module from trac:
http://trac.sitecore.net/CustomizedStartbar/ (Thanks to Alistair Deneys for this module.)

A good example of the use of the customized start bar is a startbar with Quick action buttons that open the Content editor for the master, web and core database.

image

You can download this CUSTOM customized startbar here.

Happy developing!

Webinar: Sitecore and Continuous Integration

webinar sitecore continuous integration

Today Lucas Bol gave the first Dutch Sitecore guest Webinar. The subject of this webinar was continuous integration with Sitecore based on open source products. The video is in Dutch and posted below.

[youtube]http://www.youtube.com/watch?v=Nd__rUJtLq0[/youtube]

In the next few days Lucas will post his documentation and explanation of the webinar in English. Follow us on Twitter @new_guid or subscribe to our RSS feed if you want an update when this is posted.

 

NewGuid.net live

Today we are happy to announce that NewGuid.Net is online. Newguid.net will be a weblog about Sitecore Development and sharing knowledge.  At this point all articles on NewGuid are the combination of all the articles from the personal weblogs of; Mark van Aalst and Pieter Brinkman.

We are willing to crossposts Sitecore articles and have guest Authors on this blog. If you are interested in placing your article on NewGuid.net please contact us and we’ll be happy to publish it!

Stay tune on all the nice things happening on NewGuid:

  • Subscribe to our newletter (in the sidebar)
  • Subscribe our RSS feed
  • Follow us on Twitter: @new_guid

Happy developing,
Mark and Pieter

 

Sitecore Recognizes Exceptional Technical Community Leaders From Around the World

We want to congratulate and thank all Sitecore MVP’s of 2011!


MVPs Recognized for Active Community Involvement in Advancing Web Strategies

San Francisco – April 10, 2012 – Sitecore today announced the 2011 Sitecore Most Valuable Professionals (MVPs). The program recognizes exceptional technical community leaders who serve as catalysts for change and innovation.

Sitecore MVPs voluntarily share their passion and commitment to Web technology and encourage the objective exchange of knowledge .The Sitecore MVP Award celebrates the most active Sitecore community members from around the world who provide invaluable contributions by solving problems and discovering new ways to transform technology. The program offers MVPs a number of benefits including access to technical resources such as alpha versions of Sitecore software, first release modules and full access to the Sitecore Developer Network and download section, and invitations to major events.

“MVPs are technology experts who inspire others to learn and grow through active participation in the Sitecore technical community,” said Lars Nielsen, senior vice president, technical marketing, Sitecore.  “MVPs are not just about evangelizing Sitecore. They are passionate about improving technology and driving innovation and sharing their knowledge and real-world experiences at user groups, on blogs and on social channels. This year’s prestigious list represents individuals who share the same passion for technology and a willingness to help others innovate and advance the use of Web technology. It’s my pleasure to recognize their demonstrated commitment to the technology community worldwide.”

For 2011, fifty-two outstanding individuals were selected to be members of the program and honored with a Sitecore Most Valuable Professional (MVP) Award and are as follows:                                                                  

  • Adam Najmanowicz                           Cognifide
  • Alan Gallauresi                                   NavigationArts
  • Alexander Pfandt                               Digitaria, a JWT Company
  • Alistair Deneys                                   Next Digital
  • Amanda Shiga                                    Non-linear creations
  • Anders Dryer                                      Created
  • Andrew King                                      WEtap Media
  • Andy Uzick                                        FMC Technologies
  • Aren Cambre                                       Southern Methodist University
  • Arend van de Beek                             Suneco
  • Atsuo Aoki                                         Nextscape
  • Barend van der Hout                          eFocus
  • Ben Golden                                         Aware Web Solutions
  • Brent McLean                                     Paragon Consulting
  • Brian Beckham                                   Brainjocks
  • Charlie Turano                                    Hedgehog Development
  • Chris Williams                                     Cyberplex/CX Interactive
  • Colin te Kemple                                  Consultant
  • Daniel DeLay                                      Velir
  • Daniel Tobner                                     ecx.io austria GmbH  
  • Eric Leong                                          Avanade
  • Eric Nordberg                                     Aware Web Solutions
  • Eric Briand                                          Ergonet
  • Gabriel Boys                                       Velir
  • Glen McInnis                                      Non-linear creations
  • Jakob Leander                                     Avanade Denmark
  • Jason Hedlund                                    Aware Web Solutions
  • Jens Mikkelson                                    Inmento Solutions
  • Jeroen Speldekamp                             Suneco
  • Joacim Schiodtz                                  Cabana
  • Karina Apostolides                             Endava
  • Keiichi Hashimoto                              Sigma Consulting
  • Kern Nightingale                                Herskind Limited
  • Klaus Petersen                                    Alpha Solutions
  • Lars Erhardsen                                    CometPeople
  • Mark Ursino                                        Agency Oasis
  • Matt Hovany                                       The Revere Group
  • Max Teo Wee Kwang                         Avanade
  • Mike Edwards                                    Eduserv
  • Nick Hills                                            True Clarity
  • Nick Wesselman                                 Hanson Dodge Creative
  • Paul Caponetti                                    Verndale
  • Peter Iuvara                                         mindSHIFT
  • Remco van Toor                                  iQuality
  • Richard Hauer                                     5 Limes
  • Robert Jongkind                                 eFocus
  • Roger Norrlén                                     Mogul
  • Sean Kearney                                      Hedgehog Development
  • Sebastian Winslow                              Codehouse
  • Thomas Eldblom                                 Pentia
  • Troy Lüchinger                                   Namics
  • Vincent van Middendorp                   Evident

Sitecore MVP nominees undergo an evaluation process based on each nominee’s technical expertise and voluntary community involvement over the past year. All the nominations were reviewed by an independent panel of Sitecore employees from technical, product marketing and executive roles.  The panel considers the quality, quantity, and level of impact of the nominees’ contributions, in the areas of general technical advocacy, input via blogs and forums and content development.

Sitecore has more than 4,500 certified developers, and more than 10,000 active community participants.

About Sitecore

Sitecore redefines how organizations engage with audiences, powering compelling experiences that sense and adapt to visitors both online and in-person.

Sitecore’s leading Content Management System software is the first to cohesively integrate with marketing automation, intranet portal, e-commerce, web optimization, social media and campaign management technologies. This broad choice of capabilities enable marketing professionals, business stakeholders and information technology teams to rapidly implement, measure and manage a successful website and digital  business strategy. Businesses can now easily identify, serve and convert new customers with Sitecore’s Digital Marketing System, part of its encompassing Customer Engagement Platform.

Thousands of public and private organizations have created and now manage more than 32,000 dynamic websites with Sitecore including ATP World Tour, CA Technologies, Comcast, EasyJet, Lloyd’s of London, Heineken, Microsoft, Omni Hotels, Siemens, The Knot, Thomas Cook, Verizon and Visa Europe.

Media Contact:
Kim Pegnato, Sitecore
781-620-1729
kmp@sitecore.net