Field type change


we are trying to change property type from  ContentReference to IList<ContentReference> is there any way to do that in-place or do we need to create a new field and migrate the data?

Mar 22, 2022 13:54

I think you'll need to create a new property and migrate the data.

You could have a look at MigrationStep but I'm not sure it can be used here...

Apr 04, 2022 5:49

Thomas is right in suggesting the use of MigrationStep, I've used it to create and mutate content items on site start up.  The great part is that they execute once per environment.  You'd have to use the IContent Repository to mutate your old field values onto your new fields and you'd have to iterate over all of your content items with some form of recursive lookup.  I would advise then when you save a content item within a MigrationStep that you use the following save command:

contentRepository.Save(writeablePage, SaveAction.Patch, AccessLevel.NoAccess);

SaveAction.Patch will bypass any validation errors when updating the content.  During a migration step you won't want validation errors to prevent you from converting the field.  The AccessLevel.NoAccess prevents the save event from needing a user with specific privileges to be the person triggering the save event.

An alternative tactic would be to retain both fields and use a method to access them.  If the IList<ContentReference> field is null or empty then fall back to the old ContentReference.  In the interim you could specify that the old version of the field should not be editable by decorating it with:

Apr 05, 2022 14:02
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.