Skip to main content

Sitecore

Adding Custom Fields to Sitecore User Part 1

A team of tech workers in a meeting together.

If you’re working with a Sitecore project, you would probably need to add some fields to the user profile, such as work phone, zip, or social media accounts. Most of the time, the first option to achieve this task is to add SQL tables to store the new data for each user. Still, this approach also implies overriding default behaviors, extending classes, and performing additional hard work. Fortunately, if you invest some of your time researching Sitecore documentation, you would find there is a pretty easy way to handle custom fields for Sitecore’s users… and if the situation is favorable, you could achieve the goal without a single line of code.

Customizing User Profile for User Manager

According to the documentation for Sitecore 6.0,  Sitecore maps each user with a single user profile. The profile contains the user’s basic data, such as full name, email, and portrait. It can be extended in order to add new fields that can be manipulated through the User Manager as well as by Sitecore’s API, as explained later in this post.

The trick behind extending the user profile lies in the User data template, located in the Core database, from which the additional fields could be added. There are two ways to implement custom fields:

  • Extending the Default User Profile.
    • You just need to add new fields to the existing User Profile. The change will be reflected for all users in Master Database.
  • Implementing a Custom User Profile.
    • Creates a new User Profile inheriting the Default profile; all custom fields are encapsulated in this new profile.
    • You must change at Master database the appropriate user profile through the User Manager to access the custom fields.
    • Useful for creating personalized user profiles based on the domain, country, etc.

Extending the Default User Profile for User Manager

To extend the existing profile you need to edit the User data template at the Core database, adding the sections and/or fields that you require. Once the changes were saved, all users in the Master database will be ready to set the custom values.

To perform this approach, please follow the next steps:

    1. Select the Core database
    2. Open the Template Manager and select the User item. You can find it in the following path: templates/System/Security/User
    3. Edit the template, adding the fields you need. Sections can also be added.Sitecore template manager for custom user profiles
    4. SAVE the changes
    5. Select Master database and verify the new field is displayed on the User Manager/Edit User page

Please notice the custom fields are displayed as Additional Properties in the Profile tab.

Sitecore custom user profile dialog with new fields

Implementing the Custom User Profile

The custom User Profile is created from the Default User data template. At the Core database, the User Profile data template is copied, and the custom fields are added to the copy; then, a new Profile definition must be created based on the new template. And finally, the new Profile definition must be assigned to the users in the Master database; this way, the new fields would be ready to be edited.

To implement the custom user profile, proceed with the next steps:

  1. Select Core database.
  2. Open Template Manager and duplicate the User data template. Choose a proper name for the new profile template… for exercise purposes, it will be called CustomUserProfile
    Find the user data template under templates/System/Security/User
  3. Add the custom fields in the CustomUserProfile.
  4. SAVE changes
  5. In Content Editor, select the Profile folder: System/Settings/Security/Profiles
  6. Insert the CustomUserProfileDefinition new Item for the profile definition using the CustomUserProfile data template.
    Tip: sort the CustomUserProfileDefinition at the top to be the default option when new items are created.
  7. Save your changes.
  8. Select Master database and open User Manager.
    The new profile must be available in the Master database.
    You can assign it to the desired users (existing), replace the default user profile, or add to new users.
    Once assigned to the user, you will be able to set the new fields for the selected user.
  9. Set the CustomUserProfile for the given User.
    1. In UserManager, select a user and click on the Edit command. The Edit User dialog will be displayed.
    2. In the Edit User dialog, click the Profile tab and click the Change button.
      Changing Sitecore user profile to custom user
    3. The Change User profile dialog appears.
      Please notice the profiles are sorted, displaying the CustomUserProfile at the top of the list.
      Sitecore
    4. In the Change User profile dialog, pick up the CustomUserProfile.
      The next time the user profile was displayed, the additional fields would be enabled for editing in the Profile tab in the Additional Properties section.
      Sitecore custom user profile dialog with new fields

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Categories
Follow Us