4

We have few custom fields in User profile. All users are set with data for those custom fields. I am trying to rename a custom field name in User Profile (Core DB) which results in that field value becoming empty. Again if we revert back the field name to old name then value is showing back. Please suggest.

  • Do you have custom code which references the fields by name? If so, you will need to change the names to the new names you are using – Hishaam Namooya May 10 '17 at 7:02
  • Yes. We are referencing and I have updated code to point to new field name. Thanks – Nirupama Reddy May 10 '17 at 11:29
2

User profile fields are not Sitecore.Data.Field. What you define in the custom profile is merely a mapping so that Sitecore can provide a basic UI for the user, such as this.

enter image description here

Behind the scenes, these profile fields are used with the standard ASP.NET ProfileProvider - and this uses the profile name as key. Which means you cannot rename these, and expect to keep their value.

user.Profile.SetCustomProperty("Address", address);
user.Profile.SetCustomProperty("Phone", phone);

Explained here: Sitecore users custom profile properties

3

Additional notes for Mark Cassidy's answer that, if you change the name of the user profile field in Sitecore you can migrate these values for the changed name.

So you need something like this:

foreach (var user in UserManager.GetUsers())
{
    var oldvalue = user.Profile.GetCustomProperty("Old Fields Name");
    user.Profile.SetCustomProperty("New Fields Name", oldvalue);
    user.Profile.Save();
}

Be careful because this UserManager.GetUsers() gets all users, and maybe you want to filter by domain for instance. Then you can use the Domain.GetDomain("yourdomain").GetUsers() method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.