Using xProfile Data to Populate a WFFM - Part 1: Auto-Populate a WFFM Field

Tuesday, February 23, 2016

Using xProfile Data to Populate a WFFM - Part 1: Auto-Populate a WFFM Field

By: Scott Gillis, Lead Consultant – With the addition of the Experience Database (xDB) and the Experience Profile (xProfile), we as Sitecore site owners now have more in-depth knowledge collected on visitors.

The full experience platform begins to hum and provides a targeted experience for visitors as they move from just a unique id floating through our site and become a known person. A visitor's move from just an id to a person with a 'face' is accomplished by performing an action on your site that gives some details about them. A normal way for this to occur is through the collection of information via a form, such as subscribing to an email list or requesting more information.

Once a user has become known to us, it would be nice to further engage them by cutting out a few steps in their next interaction with a WFFM form by pre-populating certain fields with information we already have collected.

Existing Field Actions

My first inclination was, there must be a WFFM field level action that accomplishes this already, given all of the talk about a contact's details being in one place via the magic of xDB. So I opened up my 'Coffee for Life' contest form to see what is available, by selecting a field (1) and clicking the Edit button (2) under Rules.

Auto-Populate WFFM Field - Image One

In the Rule Set Editor, we see there are four actions specific to WFFM. I saw "use the default value from user profile specific field" action and thought "perfect". After selecting this action, you have to enter a specific field and it is just a text box.

Auto-Populate WFFM Field - Image Two

I thought this was strange, so I opened up the rule in JetBrains' dotPeek ( The specific assembly is Sitecore.Forms.Core.dll from there you are looking for Sitecore.Forms.Core.Rules.ReadValueFromUserProfile.

The rule ends up calling an extension method that reads three properties from the User Profile. The available values are 'Comment, Full Name, or Name'. IMPORTANT NOTE: The user profile is the data stored on a user who has an account and is managed via the User Manager, this is not xProfile data. There is no direct link between a User Profile and an xProfile. (It is common to tie the two via the xProfile's Identify Identifier field, but that is a topic for another article.)

Part 1: Adding Actions to Sitecore

Custom WFFM actions, as with other rules engine actions, require two components. First, there is the action code which is then wired to a Sitecore artifact that can be used in the Rules editor.

The code for an action inherits from Sitecore.Forms.Core.Rules.ReadValue and Sitecore.Forms.Core.Rules.ConditionalRuleContext. Per old, but very helpful, Sitecore documentation, the best approach is to decompile an existing action and copy the code and use that as a starting base. To save you some time, here is what a very streamlined action template looks like:

Step two of the process is to create a Sitecore artifact that defines your action and allows it to be selected.

Auto-Populate WFFM Field - Image Three

  1. In the Content Editor, expand the System node
  2. Then, expand the Settings node
  3. Next, expand the Rules node
  4. Next, expand the Definitions node
  5. Finally, expand the Elements node
  6. You will need to scroll to the bottom of the list and locate Web Forms for Marketers Actions
  7. The last step is to right click on Web Forms for Marketers Actions, select Insert and Action
    Auto-Populate WFFM Field - Image Four 
  8. In traditional Sitecore form, provide a name for the Sitecore artifact in the modal

With an Action item now created, you will need to populate a minimum of two fields, Text and Type. The Text field (1, found under the Data section) is the verbiage displayed to the editor in the Rules Editor dialog during rule and action selection. Therefore you want this written simple enough to be easily digested but also clear enough to indicate the intent of the rule/action.

Some important details about the contents of the text field as taken from the Sitecore CMS 6.1 Rules Engine Cookbook, page 7 [].

Tokens in square brackets (--[]||) enable links allowing the user to specify parameters. The brackets contain four positional parameters separated by commas (--,||):

  1. The name of the property that the parameter sets in the .NET class that implements the condition
  2. The name of an item beneath the /Sitecore/System/Settings/Rules/Common/Macros item providing predefined functionality, or an empty string. For example, to activate a user interface allowing the user to select an item from the content tree, specify the value tree
  3. URL parameters to the user interface activated by the macro specified by the previous parameter, or an empty string. For example, to specify the /Sitecore/Content/Home item as the root for a selection tree, enter root=/sitecore/content/home
  4. Text to display if the user has not specified a value for the parameter

The second field to be concerned with is the Type field (2, found under the Script section). In this field, you will enter the class name with namespace and the assembly of your custom action.

Auto-Populate WFFM Field - Image Five


With these fields populated and your custom code deployed, you can now begin using your action set to further customize WFFM.

Auto-Populate WFFM Field - Image Six

Until part 2 is posted, you can check-out the full source solution on GitHub or, if you just want to use the macro and contact facet rule, download it from the Sitecore Marketplace. Until commenting gets implemented, feel free to tweet me questions or comments @thecodeattic or on Sitecore Slack Community as @gillissm.

Entire Series

Post One – Auto-Populate a WFFM Field - FIX ME
Post Two – Read from Contact Facet Action - FIX ME
Post Three – Rule Macro for Facet Selection - FIX ME
Post Four – Smart Form - FIX ME