Try our conversational search powered by Generative AI!

Custom property value not kept on code behind update

Vote:
 

I have implemented a custom property like the multilanguage example in this article: http://world.episerver.com/Blogs/Linus-Ekstrom/Dates/2012/9/EPiServer-7-Configuring-editors-for-your-properties/. I have however ran into something weird when working with this from codebehind and updating an existing page.

I'm using this concept to be able to control what information is to be synced to a page from a scheduled job like this

var page = (PersonPage)FindMenuPage(parentPageRef, person.PersonID.ToString(CultureInfo.InvariantCulture), "PersonPage");
            if (page != null)
            {
                var editablePage = (PersonPage)page.CreateWritableClone();
                editablePage.Name = string.Concat(person.Firstname, " ", person.Lastname);
                if (page.SyncOptions != null)
                {
                    foreach (var option in ContactSyncOptions.ToSyncOptions(page.SyncOptions))
                    {
                        var property = editablePage.GetType().GetProperty(option.PagePropertyName);
                        var propertyValue = person.GetType().GetProperty(option.ObjectPropertyName).GetValue(person);
                        property.SetValue(editablePage, propertyValue);
                    }
                }
                editablePage.URLSegment = UrlSegment.CreateUrlSegment(editablePage);
                contentRepository.Save(editablePage, SaveAction.Publish, AccessLevel.NoAccess);
            }

    

This code checks if the page exists and if it does it reads from the page which values is to be synced (SyncOptions) and then saves the pages. However I can see the correct value of the SyncOptions is set just before the Save method but after the value is empty. I can successfully set the SyncOption value from the UI but when working with it from code the value restes on save.

The code for the prooperty looks like this:

[Display(GroupName = GroupNames.SyncSettings)]
        [UIHint(SiteUIHints.SyncOptions)]
        public virtual string SyncOptions { get; set; }

        [EditorDescriptorRegistration(TargetType = typeof(string), UIHint = SiteUIHints.SyncOptions)]
        public class SyncOptionsEditorDescriptor : EditorDescriptor
        {
            public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<System.Attribute> attributes)
            {
                SelectionFactoryType = typeof(SyncOptionsSelectionFactory);
                ClientEditingClass = "epi-cms.contentediting.editors.CheckBoxListEditor";
                base.ModifyMetadata(metadata, attributes);
            }
        }

        public class SyncOptionsSelectionFactory : ISelectionFactory
        {
            public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
            {
                return ContactSyncOptions.GetSelectItems;
            }
        }

    

Has someone encountered this before or see if there is something wrong with the property setup?

#77129
Nov 11, 2013 9:24
Vote:
 

One interesting point to add. If the job has created the page with all SyncOptions checked from start. When these are changed from the ui to only have a few of them and then updated from the job it falls back to having all checked again. 

So it seems to fall back to whatever value it was created with from the beginning even if it has been changed from the UI.

#77137
Nov 11, 2013 11:59
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.