Open ziic opened 7 years ago
Does it only happen with this field? Have you tried a simple TextField?
Recently I've tried and it does NOT work correctly with a TextField too.
in my projects I usually fix it just with:
var contentItem = ContentManager.New(ContentType);
// produce root record to determine the model id
contentItem.VersionRecord = new ContentItemVersionRecord
{
ContentItemRecord = new ContentItemRecord(),
Number = 1,
Latest = true,
Published = true
};
Thanks, that's important to know, we can now check the unit tests and see if it's by design or add a new one.
I observe some strange/magic behaviour (at least since version 1.8). But only now I decided to share. Maybe I do something wrong.
Brief: If a content item of Content type with ContentPickerField is created by New method of ContentManger, later a field value is populated and next saved by Create (and/or Publish) then the field value is empty. If use immediately Create (with/without Publish) - it works correctly.
Detailed how to reproduce:
public virtual void Create(ContentItem contentItem, VersionOptions options)
method of DefaultContentManager, the value of ContentPickerField is removed after ContentItemVersionRecord is created and attached to content item. Debug Before VersionRecord Created screenshot Debug After VersionRecord Created screenshot